def test_call_var(self): """FakeRandom __call__ should work with a multi-item list""" f = FakeRandom([1, 2, 3]) self.assertEqual(f(), 1) self.assertEqual(f(), 2) self.assertEqual(f(), 3) self.assertRaises(IndexError, f)
def test_cal_var_args(self): """FakeRandom __call__ should ignore extra args""" f = FakeRandom([[1, 2, 3]], True) for i in range(5): result = f((5, 5)) # shape parameter ignored self.assertEqual(result, [1, 2, 3])
def test_call_var_wrap(self): """FakeRandom __call__ should work with a multi-item wrapped list""" f = FakeRandom([1, 2, 3], True) result = [f() for i in range(10)] self.assertEqual(result, [1, 2, 3, 1, 2, 3, 1, 2, 3, 1])
def test_call_constant_wrap(self): """FakeRandom __call__ should wrap for one-item list if specified""" const = FakeRandom([1], True) for i in range(10): self.assertEqual(const(), True)
def test_call_constant(self): """FakeRandom __call__ should return next item from list if constant""" const = FakeRandom([1]) self.assertEqual(const(), 1) self.assertRaises(IndexError, const)