MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_unit_globals

Function test_unit_globals

scripts/test_stringzilla.py:688–765  ·  view source on GitHub ↗

Validates that the previously unit-tested member methods are also visible as global functions.

()

Source from the content-addressed store, hash-verified

686
687
688def test_unit_globals():
689 """Validates that the previously unit-tested member methods are also visible as global functions."""
690
691 assert sz.find("abcdef", "bcdef") == 1
692 assert sz.find("abcdef", "x") == -1
693 assert sz.rfind("abcdef", "bcdef") == 1
694 assert sz.rfind("abcdef", "x") == -1
695
696 # Corner-cases for `find` and `rfind`, when we pass empty strings
697 assert sz.find("abcdef", "") == "abcdef".find("")
698 assert sz.rfind("abcdef", "") == "abcdef".rfind("")
699 assert sz.find("abcdef", "", 1) == "abcdef".find("", 1)
700 assert sz.rfind("abcdef", "", 1) == "abcdef".rfind("", 1)
701 assert sz.find("abcdef", "", 1, 3) == "abcdef".find("", 1, 3)
702 assert sz.rfind("abcdef", "", 1, 3) == "abcdef".rfind("", 1, 3)
703 assert sz.find("", "abcdef") == "".find("abcdef")
704 assert sz.rfind("", "abcdef") == "".rfind("abcdef")
705
706 assert sz.find("Hello, world!", "world", 0, 11) == "Hello, world!".find("world", 0, 11)
707 assert sz.rfind("Hello, world!", "world", 0, 11) == "Hello, world!".rfind("world", 0, 11)
708
709 assert sz.find_first_of("abcdef", "cde") == 2
710 assert sz.find_first_of("abcdef", "xyz") == -1
711 assert sz.find_first_of("hello world", "aeiou") == 1
712
713 assert sz.find_last_of("abcdef", "abc") == 2
714 assert sz.find_last_of("abcdef", "xyz") == -1
715 assert sz.find_last_of("hello world", "aeiou") == 7
716
717 assert sz.find_first_not_of("aaabbbccc", "ab") == 6
718 assert sz.find_first_not_of("abcdef", "abcdef") == -1
719 assert sz.find_first_not_of(" hello", " ") == 3
720
721 assert sz.find_last_not_of("aaabbbccc", "bc") == 2
722 assert sz.find_last_not_of("abcdef", "abcdef") == -1
723 assert sz.find_last_not_of("hello ", " ") == 4
724
725 # Test byteset counting
726 assert sz.count_byteset("abcdef", "abc") == 3
727 assert sz.count_byteset("abcdef", "xyz") == 0
728 assert sz.count_byteset("hello world", "aeiou") == 3 # e, o, o
729 assert sz.count_byteset("mississippi", "si") == 8 # s, i, s, s, i, s, s, i
730 assert sz.count_byteset("", "abc") == 0
731 assert sz.count_byteset("abc", "") == 0
732 assert sz.count_byteset("abcdef", "abc", 1, 4) == 2 # bc in "bcd"
733 assert sz.count_byteset("hello world", "aeiou", 2) == 2 # o, o
734 assert sz.count_byteset("hello world", "aeiou", 0, 5) == 2 # e, o in "hello"
735
736 # Compare partitioning functions
737 assert sz.partition("abcdef", "c") == ("ab", "c", "def")
738 assert sz.rpartition("abcdef", "c") == ("ab", "c", "def")
739
740 with pytest.raises(ValueError):
741 sz.partition("abcdef", "")
742 with pytest.raises(ValueError):
743 sz.rpartition("abcdef", "")
744
745 assert sz.count("abcdef", "x") == 0

Callers

nothing calls this directly

Calls 12

partitionMethod · 0.80
rpartitionMethod · 0.80
countMethod · 0.80
splitMethod · 0.80
rsplitMethod · 0.80
findMethod · 0.45
rfindMethod · 0.45
find_first_ofMethod · 0.45
find_last_ofMethod · 0.45
find_first_not_ofMethod · 0.45
find_last_not_ofMethod · 0.45
bytesumMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…