示例#1
0
 def test_range_start_stop_step(self):
     steps = Steps(3)
     start = 2
     tests = {
         -4: {-16, -15, -14, -13},
         -3: {-12, -11, -10},
         -2: {-8, -7},
         -1: {-4},
         0: {},
         1: {4},
         2: {7, 8},
         3: {10, 11, 12},
         4: {13, 14, 15, 16},
     }
     for step in sorted(tests):
         validstops = tests[step]
         for base in range(-20, 21):
             stop = base + start
             with self.subTest((start, stop, step)):
                 if base in validstops:
                     r = steps.range(start=start, stop=stop, step=step)
                     self.assertEqual(r, range(start, stop, step))
                     self.assertEqual(len(r), len(steps))
                 else:
                     with self.assertRaises(ValueError):
                         steps.range(start=start, stop=stop, step=step)
示例#2
0
    def test_range_no_start_no_stop_step(self):
        steps = Steps(3)
        r_inc = steps.range(step=2)
        r_dec = steps.range(step=-2)

        self.assertEqual(r_inc, range(0, 8, 2))
        self.assertEqual(len(r_inc), len(steps))
        self.assertEqual(r_dec, range(0, -8, -2))
        self.assertEqual(len(r_dec), len(steps))
示例#3
0
    def test_range_no_start_stop_step(self):
        steps = Steps(3)
        r_inc = steps.range(stop=3, step=2)
        r_dec = steps.range(stop=3, step=-2)

        self.assertEqual(r_inc, range(-5, 3, 2))
        self.assertEqual(len(r_inc), len(steps))
        self.assertEqual(r_dec, range(11, 3, -2))
        self.assertEqual(len(r_dec), len(steps))
示例#4
0
    def test_range_no_start_stop_no_step(self):
        steps = Steps(3)
        r1 = steps.range(stop=3)
        r2 = steps.range(stop=-3)

        self.assertEqual(r1, range(-1, 3, 1))
        self.assertEqual(len(r1), len(steps))
        self.assertEqual(r2, range(-7, -3, 1))
        self.assertEqual(len(r2), len(steps))
示例#5
0
    def test_range_start_stop_no_step_invalid(self):
        steps = Steps(3)
        start = 2

        invalid = [
            -9,
            -6,
            -5,
            -3,
            -2,
            -1,
            0,
            1,
            2,
            3,
            5,
            6,
            9,
        ]
        for stop in invalid:
            stop += start
            with self.subTest((start, stop)):
                with self.assertRaises(ValueError):
                    steps.range(start=start, stop=stop)
示例#6
0
    def test_range_start_stop_no_step_valid(self):
        steps = Steps(3)
        start = 2

        tests = {
            -5: [-18, -17, -16],
            -4: [-15, -14, -13],
            -3: [-12, -11, -10],
            -2: [-8, -7],
            -1: [-4],
            1: [4],
            2: [7, 8],
            3: [10, 11, 12],
            4: [13, 14, 15],
            5: [16, 17, 18],
        }
        for step in sorted(tests):
            for stop in tests[step]:
                stop += start
                with self.subTest((start, stop, step)):
                    r = steps.range(start=start, stop=stop)
                    self.assertEqual(r, range(start, stop, step))
                    self.assertEqual(len(r), len(steps))
示例#7
0
    def test_range_no_start_no_stop_no_step(self):
        steps = Steps(3)
        r = steps.range()

        self.assertEqual(r, range(4))
        self.assertEqual(len(r), len(steps))
示例#8
0
    def test_range_start_no_stop_step(self):
        steps = Steps(3)
        r = steps.range(start=4, step=2)

        self.assertEqual(r, range(4, 12, 2))
        self.assertEqual(len(r), len(steps))