On Sunday, June 13, 2021 at 2:35:42 PM UTC-4 Brian Candler wrote: > On Sunday, 13 June 2021 at 16:09:48 UTC+1 kee...@gmail.com wrote: > >> For my heap, I never had to Push or Pop, I only had to initialize the >> heap and repeatedly "Fix" the top element of the heap. As it turns out the >> Init and Fix functions only use the 3 sorting methods of the heap. They >> don't use Push or Pop. So when I ran test coverage, I found that my Push >> and Pop implementations weren't covered. I can't leave my Push and Pop >> implementation out because the Init and Fix methods require heaps with all >> 5 methods. What do I do? > > > Add some unit tests (in your own application) that call heap.Push or > heap.Pop on your heap type. That will give you the test coverage. > > If you don't like carrying dead code, then you could replace your Push and > Pop with panic() - but you'll still want unit tests that test that they > panic, for your coverage report. > > You could argue that heap.Init and heap.Fix could take a sort.Interface > rather than a heap.Interface. However that exposes internals, and it would > limit backwards-compatible versions of those functions. >
In fact I would go even further and argue that it would be *technically *incorrect to use the Init() and Fix() methods without fully implementing the interface required by the documentation. As Brian pointed out, the fact that they are not used is an implementation detail. Unless I missed something that is not documented. As a reasonable compromise, I would definitely implement the 'missing' methods using panic(), as a hedge against future changes. I will admit, I can not really see the implementation changing to use Push() and Pop(), but it seems like good practice and hygiene. (I also use my car directional signals even when no one is behind me ... better to just keep in the habit of being safe.) -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/10c16d77-4d05-480c-a1f3-c8c159e306c5n%40googlegroups.com.