public void should_throw_exception_if_no_value_in_dictionary_below_the_key() { SortedDictionary <double, double> collection = new SortedDictionary <double, double> { { 0.25, 1 }, { 0.5, 3 }, { 0.75, 4 }, { 1, 9 }, { 1.25, 10 }, { 1.5, 16 }, { 2, 18 }, { 3, 21 }, { 4, 34 }, { 5, 18 }, { 6, 21 }, { 7, 34 }, { 8, 18 }, { 9, 21 }, { 10, 34 } }; double val1 = 0.25; double val2 = -1; int nbExceptions = 0; try { double key1 = Tools.FindHighestBelow(collection, val1); } catch (Exception e) { nbExceptions++; } try { double key2 = Tools.FindHighestBelow(collection, val2); } catch (Exception e) { nbExceptions++; } Assert.IsTrue(nbExceptions == 2); }
public void should_return_highest_below_value_for_first_and_intermidiate_elements() { SortedDictionary <double, double> collection = new SortedDictionary <double, double> { { 0.25, 1 }, { 0.5, 3 }, { 0.75, 4 }, { 1, 9 }, { 1.25, 10 }, { 1.5, 16 }, { 2, 18 }, { 3, 21 }, { 4, 34 }, { 5, 18 }, { 6, 21 }, { 7, 34 }, { 8, 18 }, { 9, 21 }, { 10, 34 } }; double val1 = 0.26; double val2 = 2.12; double val3 = 9.25; double val4 = 10.4; double key1 = -1; double key2 = -1; double key3 = -1; double key4 = -1; try { key1 = Tools.FindHighestBelow(collection, val1); key2 = Tools.FindHighestBelow(collection, val2); key3 = Tools.FindHighestBelow(collection, val3); key4 = Tools.FindHighestBelow(collection, val4); } catch (Exception e) { } Assert.IsTrue(key1.Equals(0.25) && key2.Equals(2) && key3.Equals(9) && key4.Equals(10)); }