diff options
| author | xbe <xbe@machine> | 2014-03-12 22:57:16 -0700 |
|---|---|---|
| committer | xbe <xbe@machine> | 2014-03-12 22:57:16 -0700 |
| commit | 9e1e8cd6428e875eb29be98124ee3b1ba2bace30 (patch) | |
| tree | be21ee15a324d83b28851395182d925d091b12ef /tests | |
| parent | 19438fd30a3184b656221a59062ea32453d0fd16 (diff) | |
Implement str.count and add tests for it.
Also modify mp_get_index to accept:
1. Indices that are or evaluate to a boolean.
2. Slice indices.
Add tests for these two cases.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/list_index.py | 10 | ||||
| -rw-r--r-- | tests/basics/string_count.py | 21 | ||||
| -rw-r--r-- | tests/basics/string_find.py | 12 |
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/basics/list_index.py b/tests/basics/list_index.py index f28263fba..a669e69c4 100644 --- a/tests/basics/list_index.py +++ b/tests/basics/list_index.py @@ -3,6 +3,16 @@ print(a.index(1)) print(a.index(2)) print(a.index(3)) print(a.index(3, 2)) +print(a.index(1, -100)) +print(a.index(1, False)) + +try: + print(a.index(1, True)) +except ValueError: + print("Raised ValueError") +else: + print("Did not raise ValueError") + try: print(a.index(3, 2, 2)) except ValueError: diff --git a/tests/basics/string_count.py b/tests/basics/string_count.py new file mode 100644 index 000000000..42f807c93 --- /dev/null +++ b/tests/basics/string_count.py @@ -0,0 +1,21 @@ +print("asdfasdfaaa".count("asdf", -100)) +print("asdfasdfaaa".count("asdf", -8)) +print("asdf".count('s', True)) +print("asdf".count('a', True)) +print("asdf".count('a', False)) +print("asdf".count('a', 1 == 2)) +print("hello world".count('l')) +print("hello world".count('l', 5)) +print("hello world".count('l', 3)) +print("hello world".count('z', 3, 6)) +print("aaaa".count('a')) +print("aaaa".count('a', 0, 3)) +print("aaaa".count('a', 0, 4)) +print("aaaa".count('a', 0, 5)) +print("aaaa".count('a', 1, 5)) +print("aaaa".count('a', -1, 5)) + +def t(): + return True + +print("0000".count('0', t())) diff --git a/tests/basics/string_find.py b/tests/basics/string_find.py index 90063228f..df65fd6e5 100644 --- a/tests/basics/string_find.py +++ b/tests/basics/string_find.py @@ -9,3 +9,15 @@ print("hello world".find("ll", 1, 2)) print("hello world".find("ll", 1, 3)) print("hello world".find("ll", 1, 4)) print("hello world".find("ll", 1, 5)) +print("hello world".find("ll", -100)) +print("0000".find('0')) +print("0000".find('0', 0)) +print("0000".find('0', 1)) +print("0000".find('0', 2)) +print("0000".find('0', 3)) +print("0000".find('0', 4)) +print("0000".find('0', 5)) +print("0000".find('-1', 3)) +print("0000".find('1', 3)) +print("0000".find('1', 4)) +print("0000".find('1', 5)) |
