Example #1
0
 def test_naturals(self):
     nats = hacklib.Naturals()
     takefive = hacklib.take(nats, 5)
     assert takefive == [1, 2, 3, 4, 5]
     assert 12 in nats
     assert -5 not in nats
     assert 12.3 not in nats
Example #2
0
 def test_convergents(self):
     euler = hacklib.Convergents.of_e()
     test = hacklib.take(euler, 4)
     assert test[0] == fractions.Fraction(2, 1)
     assert test[1] == fractions.Fraction(3, 1)
     assert test[2] == fractions.Fraction(8, 3)
     assert test[3] == fractions.Fraction(11, 4)
Example #3
0
 def test_abundants(self):
     abund = hacklib.Abundants()
     test = hacklib.take(abund, 5)
     assert test == [12, 18, 20, 24, 30]
     assert 20 in abund
     assert 102 in abund
     assert 118 not in abund
Example #4
0
 def test_squares(self):
     squares = hacklib.Squares()
     takefive = hacklib.take(squares, 5)
     for num in takefive:
         assert num in squares
     assert takefive == [1, 4, 9, 16, 25]
     assert 17 not in takefive
     assert -1 not in takefive
Example #5
0
 def test_triangulars(self):
     tries = hacklib.Triangulars()
     taketen = hacklib.take(tries, 10)
     correct = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
     assert taketen == correct
     assert 28 in tries
     assert 29 not in tries
     assert 27 not in tries
     assert -6 not in tries
Example #6
0
 def test_pentagonals(self):
     pents = hacklib.Pentagonals()
     correct = [1, 5, 12, 22, 35, 51, 70, 92, 117, 145]
     for num in correct:
         assert num in pents
     taketen = hacklib.take(pents, 10)
     assert taketen == correct
     assert 442 not in pents
     assert 6 not in pents
Example #7
0
 def test_fibonacci(self):
     fibs = [0, 1, 1, 2, 3, 5, 8, 13, 21]
     fibseq = hacklib.ArithSequence(0, 1)
     taketen = hacklib.take(fibseq, len(fibs))
     for x in range(len(fibs)):
         assert taketen[x] == fibs[x]
     assert 5 in fibseq
     assert 7 not in fibseq
     assert 8 in fibseq
     assert 144 in fibseq