-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjsonops_tests.py
executable file
·103 lines (73 loc) · 2.77 KB
/
jsonops_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
import unittest
from bin.lib import jsonops
import json
class Array_slice_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(
jsonops.array_slice([], 1, 2) == jsonops.pprint([]))
def test_one(self):
self.failUnless(
jsonops.array_slice([1], 0, 1) == jsonops.pprint([1]))
def test_normal_slice(self):
self.failUnless(
jsonops.array_slice(range(10), 3, 5) == jsonops.pprint([3, 4]))
def test_reverse_range(self):
self.failUnless(
jsonops.array_slice(range(10), 9, 1) == jsonops.pprint([]))
class Array_head_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(
jsonops.array_head([], 1) == jsonops.pprint([]))
def test_one(self):
self.failUnless(
jsonops.array_head([1], 1) == jsonops.pprint([1]))
def test_normal(self):
self.failUnless(
jsonops.array_head(range(9), 3) == jsonops.pprint([0, 1, 2]))
def test_out_of_range(self):
self.failUnless(
jsonops.array_head(range(3), 11) == jsonops.pprint([0, 1, 2]))
class Array_tail_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(
jsonops.array_tail([], 1) == jsonops.pprint([]))
def test_one(self):
self.failUnless(
jsonops.array_tail([1], 0) == jsonops.pprint([1]))
def test_normal(self):
self.failUnless(
jsonops.array_tail(range(9), 7) == jsonops.pprint([7, 8]))
def test_out_of_range(self):
self.failUnless(
jsonops.array_tail(range(3), 7) == jsonops.pprint([]))
class Object_get_tests(unittest.TestCase):
def test_strings(self):
self.failUnless(
jsonops.object_get({"f": "b", "z": "q"}, "z")
== jsonops.pprint("q"))
class Object_keys_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(jsonops.object_keys({}) == jsonops.pprint([]))
def test_normal(self):
self.failUnless(
jsonops.object_keys({"1": "a", "2": "b"})
== jsonops.pprint(["1", "2"]))
class Object_values_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(jsonops.object_values({}) == jsonops.pprint([]))
def test_normal(self):
self.failUnless(
jsonops.object_values({"1": "a", "2": "b"})
== jsonops.pprint(["a", "b"]))
class Object_values_tests(unittest.TestCase):
def test_empty(self):
self.failUnless(jsonops.array_enumerate([], "4") == jsonops.pprint({}))
def test_normal(self):
self.failUnless(
jsonops.array_enumerate({"a", "b"}, 4)
== jsonops.pprint({4: "a", 5: "b"}))
def main():
unittest.main()
if __name__ == '__main__':
main()