Exemple #1
0
 def test_powers_of_two(self):
     """Test iterator for all powers of two less than a given number."""
     pow2 = powers_of_two(70)
     self.assertEqual(next(pow2), 1)
     self.assertEqual(next(pow2), 2)
     self.assertEqual(next(pow2), 4)
     self.assertEqual(next(pow2), 8)
     self.assertEqual(next(pow2), 16)
     self.assertEqual(next(pow2), 32)
     self.assertEqual(next(pow2), 64)
     pow2 = powers_of_two(2)
     self.assertEqual(next(pow2), 1)
     self.assertEqual(next(pow2), 2)
Exemple #2
0
 def test_powers_of_two_produces_an_actual_generator(self):
     g = powers_of_two(3)
     self.assertEqual(g.next(), 1)
     self.assertEqual(g.next(), 2)
     self.assertRaises(StopIteration, g.next)
Exemple #3
0
 def test_powers_of_two_produces_correct_sequences(self):
     self.assertEqual(list(powers_of_two(60)), [1, 2, 4, 8, 16, 32])
     self.assertEqual(list(powers_of_two(63)), [1, 2, 4, 8, 16, 32])
     self.assertEqual(list(powers_of_two(64)), [1, 2, 4, 8, 16, 32, 64])
     self.assertEqual(list(powers_of_two(0)), [])
     self.assertEqual(list(powers_of_two(1)), [1])
Exemple #4
0
 def test_powers_of_two_produces_an_actual_generator(self):
     g = powers_of_two(3)
     self.assertEqual(g.next(), 1)
     self.assertEqual(g.next(), 2)
     self.assertRaises(StopIteration, g.next)
Exemple #5
0
 def test_powers_of_two_produces_correct_sequences(self):
     self.assertEqual(list(powers_of_two(60)), [1, 2, 4, 8, 16, 32])
     self.assertEqual(list(powers_of_two(63)), [1, 2, 4, 8, 16, 32])
     self.assertEqual(list(powers_of_two(64)), [1, 2, 4, 8, 16, 32, 64])
     self.assertEqual(list(powers_of_two(0)), [])
     self.assertEqual(list(powers_of_two(1)), [1])