def test_equal_sized_breakpoints(self): self.assertEqual( calculate.equal_sized_breakpoints(list(range(1, 101)), 5), [1.0, 21.0, 41.0, 61.0, 81.0, 100.0] ) self.assertEqual( calculate.equal_sized_breakpoints([1, 2, 3, 4, 5], 2), [1.0, 3.5, 5.0] ) self.assertEqual( calculate.equal_sized_breakpoints([1, 2, 3, 4, 5, 6], 2), [1.0, 4.0, 6.0] ) self.assertRaises( TypeError, calculate.equal_sized_breakpoints, ['foo', 'bar', 'baz'], 2 ) self.assertRaises( TypeError, calculate.equal_sized_breakpoints, list(range(1, 101)), 'a' )
def test_equal_sized_breakpoints(self): self.assertEqual( calculate.equal_sized_breakpoints(list(range(1, 101)), 5), [1.0, 21.0, 41.0, 61.0, 81.0, 100.0]) self.assertEqual(calculate.equal_sized_breakpoints([1, 2, 3, 4, 5], 2), [1.0, 3.5, 5.0]) self.assertEqual( calculate.equal_sized_breakpoints([1, 2, 3, 4, 5, 6], 2), [1.0, 4.0, 6.0]) self.assertRaises(TypeError, calculate.equal_sized_breakpoints, ['foo', 'bar', 'baz'], 2) self.assertRaises(TypeError, calculate.equal_sized_breakpoints, list(range(1, 101)), 'a')
def test_split_at_breakpoints(self): l = list(range(1, 31)) bp = calculate.equal_sized_breakpoints(l, 5) self.assertEqual(bp, [1.0, 7.0, 13.0, 19.0, 25.0, 30.0]) self.assertEqual( calculate.split_at_breakpoints(l, bp), [ [1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30] ] ) self.assertRaises( Exception, calculate.split_at_breakpoints, ['foo', 'bar', 'baz'], bp, ) self.assertRaises( Exception, calculate.split_at_breakpoints, l, ['foo', 'bar', 'baz'], )
def test_split_at_breakpoints(self): l = list(range(1, 31)) bp = calculate.equal_sized_breakpoints(l, 5) self.assertEqual(bp, [1.0, 7.0, 13.0, 19.0, 25.0, 30.0]) self.assertEqual(calculate.split_at_breakpoints(l, bp), [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30]]) self.assertRaises( Exception, calculate.split_at_breakpoints, ['foo', 'bar', 'baz'], bp, ) self.assertRaises( Exception, calculate.split_at_breakpoints, l, ['foo', 'bar', 'baz'], )