The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

2

There isn't anything inherently wrong with repeating assertions in the same test, and for few test case values like yours this is perfectly fine. But if you need to test a large set of values, consider using a parameterized test like the following: @RunWith(org.junit.runners.Parameterized.class) public class SortedOrNotTest { @Parameterized.Parameter(0)...


2

Tests like these often involve a lot of copy-pasted boilerplate and that increases tremendously the effort required to maintain the tests. Instead of writing an assert statement for each array or a separate test method for each case, you could store the arrays into two lists; those that should be detected as sorted and those that should not be and process ...


3

I don't see anything wrong with the way you are testing. You may want to include negative numbers in your test cases. I prefer to have test cases broken up. It's easier to track down failing tests: @Test public void testIsSortedSingleNode() { int[] C = { 32 }; assertEquals(true, SortedOrNot.isSorted(C)); } Even in tests you should follow naming ...


1

Small issue if (!map.containsKey(element)) { return false; } Node<E, P> node = map.get(element); You can simply write Node<E, P> node = map.get(element); and check if node is null. This increases performance and atomicity. Design issue I think you could improve readability if you split the implementation to a Doubly-...


1

An offline code review came up with a critical piece of feedback: The constructor for Task takes an Action<T>. The async delegate therefore generates an async void method, which has 2 implications: If an unhandled exception is thrown from the async void method, it will crash the process (unlikely, since it's just calling Task.Delay(), but it's an ...


1

This mostly a response to your comment, but I feel it really shouldn't be another comment. I guess I should have also done the following (?): 1) returned a helpful error message if a non-string argument was given to get_anagrams() and created a unit test for this 2) Created unit test for get_anagrams() with empty string argument (although I think this is ...


1

For an interview, I would test everything very thoroughly. The public interface consists of Anagrams(), Anagrams.initialise(), and Anagrams.get_anagram(). The public interface also includes the fact that initialise() needs to be called before get_anagram() and the format of text file. So test everything: For Anagram(filename): (some of these errors don'...


2

MainPageViewModel You provide an interface with a single method: public interface IMainPageViewModel { void LoadGroups(); } Yet, the implementation provides a rich set of public members: public string FileLocation { get; set; } public ObservableCollection<string> Groups { get; set; } public List<Phrase> LoadedPhrases { get; set; } public ...


2

You could use Iterator:any to write this in a succinct way: fn string_ends_with_any(s: String, suffixes: Vec<&str>) -> bool { return suffixes.iter().any(|&suffix| s.ends_with(suffix)); } Because this pattern returns true on first match of the predicate: for suffix in &suffixes { if s.ends_with(suffix) { return true; ...


2

Packaging The project and repository is called cl-binheap, while the ASDF system is called binheap - it's a good idea for those to match, mostly due to UX: I'll try loading the repository name first all the time. Worse is the package name binhp. Now we have three names instead of one. Simply pick one of them and go with it (not binhp though, why's ...


1

I would personally prefer a simpler approach, using System.Reactive (Rx.NET): public abstract class ViewModel : INotifyPropertyChanged { public ViewModel(int throttlingPeriod = 250) : this(TimeSpan.FromMilliseconds(throttlingPeriod)) { } public ViewModel(TimeSpan throttlingPeriod) { Subject = new Subject<string>(); ...


Top 50 recent answers are included