Sha256: f46b46c6733c1b03692ba401e5921962eba3356c994f3804a3850f2e115285e5
Contents?: true
Size: 1.42 KB
Versions: 127
Compression:
Stored size: 1.42 KB
Contents
import unittest from strain import keep, discard class StrainTest(unittest.TestCase): def test_empty_sequence(self): self.assertEqual([], keep([], lambda x: x % 2 == 0)) def test_empty_keep(self): inp = [2, 4, 6, 8, 10] out = [] self.assertEqual(out, keep(inp, lambda x: x % 2 == 1)) def test_empty_discard(self): inp = [2, 4, 6, 8, 10] out = [] self.assertEqual(out, discard(inp, lambda x: x % 2 == 0)) def test_keep_everything(self): inp = [2, 4, 6, 8, 10] self.assertEqual(inp, keep(inp, lambda x: x % 2 == 0)) def test_discard_endswith(self): inp = ['dough', 'cash', 'plough', 'though', 'through', 'enough'] out = ['cash'] self.assertEqual(out, discard(inp, lambda x: str.endswith(x, 'ough'))) def test_keep_z(self): inp = ['zebra', 'arizona', 'apple', 'google', 'mozilla'] out = ['zebra', 'arizona', 'mozilla'] self.assertEqual(out, keep(inp, lambda x: 'z' in x)) def test_keep_discard(self): inp = ['1,2,3', 'one', 'almost!', 'love'] self.assertEqual([], discard(keep(inp, str.isalpha), str.isalpha)) def test_keep_plus_discard(self): inp = ['1,2,3', 'one', 'almost!', 'love'] out = ['one', 'love', '1,2,3', 'almost!'] self.assertEqual(out, keep(inp, str.isalpha) + discard(inp, str.isalpha)) if __name__ == '__main__': unittest.main()
Version data entries
127 entries across 127 versions & 1 rubygems