Skip to main content

oxilean_std/string/
functions_2.rs

1//! Auto-generated module
2//!
3//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
4
5use super::functions::*;
6use oxilean_kernel::{Declaration, Environment, Expr, Level, Name};
7
8use super::types::{
9    LevenshteinMetric2, RollingHashExt, StringEncoderExt, StringMonoidExt, SubstringFinder2,
10};
11
12#[cfg(test)]
13mod str_ext2_tests {
14    use super::*;
15    #[test]
16    fn test_register_string_extended_axioms() {
17        let mut env = oxilean_kernel::Environment::new();
18        register_string_extended_axioms(&mut env);
19        assert!(env.contains(&Name::str("String.Ext.ConcatAssoc")));
20        assert!(env.contains(&Name::str("String.Ext.KmpCorrect")));
21        assert!(env.contains(&Name::str("String.Ext.EditDistTriangle")));
22        assert!(env.contains(&Name::str("String.Ext.SuffixArraySorted")));
23        assert!(env.contains(&Name::str("String.Ext.Utf8Roundtrip")));
24    }
25    #[test]
26    fn test_str_concat_assoc() {
27        assert!(str_concat_assoc_check("foo", "bar", "baz"));
28    }
29    #[test]
30    fn test_str_left_id() {
31        assert!(str_left_id_check("hello"));
32        assert!(str_left_id_check(""));
33    }
34    #[test]
35    fn test_str_right_id() {
36        assert!(str_right_id_check("world"));
37        assert!(str_right_id_check(""));
38    }
39    #[test]
40    fn test_str_length_additive() {
41        assert!(str_length_additive("hello", " world"));
42        assert!(str_length_additive("", "abc"));
43    }
44    #[test]
45    fn test_str_lex_lt_irrefl() {
46        assert!(str_lex_lt_irrefl("apple"));
47        assert!(str_lex_lt_irrefl(""));
48    }
49    #[test]
50    fn test_str_lex_lt_trans() {
51        assert!(str_lex_lt_trans("apple", "banana", "cherry"));
52        assert!(str_lex_lt_trans("z", "a", "m"));
53    }
54    #[test]
55    fn test_str_substring() {
56        assert_eq!(str_substring("hello world", 6, 5), "world");
57        assert_eq!(str_substring("hello", 0, 3), "hel");
58    }
59    #[test]
60    fn test_str_prefix_refl() {
61        assert!(str_prefix_refl("hello"));
62        assert!(str_prefix_refl(""));
63    }
64    #[test]
65    fn test_str_prefix_trans() {
66        assert!(str_prefix_trans("he", "hel", "hello"));
67        assert!(str_prefix_trans("x", "xy", "z"));
68    }
69    #[test]
70    fn test_str_split_join_roundtrip() {
71        assert!(str_split_join_roundtrip("a,b,c", ","));
72        assert!(str_split_join_roundtrip("hello", ","));
73        assert!(str_split_join_roundtrip("", ","));
74    }
75    #[test]
76    fn test_str_trim_idempotent() {
77        assert!(str_trim_idempotent("  hello  "));
78        assert!(str_trim_idempotent("clean"));
79        assert!(str_trim_idempotent(""));
80    }
81    #[test]
82    fn test_str_to_upper_idempotent() {
83        assert!(str_to_upper_idempotent("Hello World"));
84        assert!(str_to_upper_idempotent("ALREADY UPPER"));
85    }
86    #[test]
87    fn test_str_to_lower_idempotent() {
88        assert!(str_to_lower_idempotent("Hello World"));
89        assert!(str_to_lower_idempotent("already lower"));
90    }
91    #[test]
92    fn test_str_contains_refl() {
93        assert!(str_contains_refl("hello"));
94        assert!(str_contains_refl(""));
95    }
96    #[test]
97    fn test_str_find_replace() {
98        assert_eq!(
99            str_find_replace("hello world", "world", "Rust"),
100            "hello Rust"
101        );
102        assert_eq!(str_find_replace("aaa", "a", "b"), "bbb");
103    }
104    #[test]
105    fn test_str_replace_id() {
106        assert!(str_replace_id("hello world", "world"));
107        assert!(str_replace_id("test", "xyz"));
108    }
109    #[test]
110    fn test_str_utf8_roundtrip() {
111        assert!(str_utf8_roundtrip("hello"));
112        assert!(str_utf8_roundtrip(""));
113        assert!(str_utf8_roundtrip("Unicode: \u{00E9}"));
114    }
115    #[test]
116    fn test_str_utf16_len() {
117        let s = "hello";
118        assert_eq!(str_utf16_len(s), 5);
119    }
120    #[test]
121    fn test_str_char_to_string() {
122        assert_eq!(str_char_to_string('A'), "A");
123    }
124    #[test]
125    fn test_str_hash_consistent() {
126        assert!(str_hash_consistent("hello", "hello"));
127        assert!(str_hash_consistent("a", "b"));
128    }
129    #[test]
130    fn test_str_kmp_search() {
131        let positions = str_kmp_search("ababab", "ab");
132        assert_eq!(positions, vec![0, 2, 4]);
133    }
134    #[test]
135    fn test_str_rabin_karp_search() {
136        let positions = str_rabin_karp_search("ababab", "ab");
137        assert_eq!(positions, vec![0, 2, 4]);
138    }
139    #[test]
140    fn test_str_kmp_matches_naive() {
141        assert!(str_kmp_matches_naive("hello world", "world"));
142        assert!(str_kmp_matches_naive("ababab", "ab"));
143        assert!(str_kmp_matches_naive("no match", "xyz"));
144    }
145    #[test]
146    fn test_str_rabin_karp_matches_kmp() {
147        assert!(str_rabin_karp_matches_kmp("hello world", "world"));
148        assert!(str_rabin_karp_matches_kmp("ababab", "ab"));
149    }
150    #[test]
151    fn test_str_aho_corasick_search() {
152        let results = str_aho_corasick_search("hello world", &["hello", "world"]);
153        assert_eq!(results.len(), 2);
154    }
155    #[test]
156    fn test_str_suffix_array() {
157        let sa = str_suffix_array("banana");
158        assert_eq!(sa.len(), 6);
159    }
160    #[test]
161    fn test_str_suffix_array_sorted() {
162        assert!(str_suffix_array_sorted("banana"));
163        assert!(str_suffix_array_sorted("abcdef"));
164        assert!(str_suffix_array_sorted(""));
165    }
166    #[test]
167    fn test_str_lcp_array() {
168        let lcp = str_lcp_array("banana");
169        assert_eq!(lcp.len(), 6);
170    }
171    #[test]
172    fn test_str_levenshtein() {
173        assert_eq!(str_levenshtein("kitten", "sitting"), 3);
174        assert_eq!(str_levenshtein("", "abc"), 3);
175        assert_eq!(str_levenshtein("abc", "abc"), 0);
176    }
177    #[test]
178    fn test_str_edit_dist_zero() {
179        assert!(str_edit_dist_zero("hello"));
180        assert!(str_edit_dist_zero(""));
181    }
182    #[test]
183    fn test_str_edit_dist_sym() {
184        assert!(str_edit_dist_sym("kitten", "sitting"));
185        assert!(str_edit_dist_sym("abc", "xyz"));
186    }
187    #[test]
188    fn test_str_edit_dist_triangle() {
189        assert!(str_edit_dist_triangle("abc", "abd", "xyz"));
190        assert!(str_edit_dist_triangle("", "a", "ab"));
191    }
192    #[test]
193    fn test_str_unicode_valid() {
194        assert!(str_unicode_valid("hello"));
195        assert!(str_unicode_valid("\u{00E9}"));
196    }
197    #[test]
198    fn test_str_count_alnum() {
199        assert_eq!(str_count_alnum("hello world 123"), 13);
200        assert_eq!(str_count_alnum("!@#$"), 0);
201    }
202    #[test]
203    fn test_str_dec_eq_refl() {
204        assert!(str_dec_eq_refl("hello"));
205        assert!(str_dec_eq_refl(""));
206    }
207    #[test]
208    fn test_str_dec_eq_sym() {
209        assert!(str_dec_eq_sym("abc", "abc"));
210        assert!(str_dec_eq_sym("abc", "xyz"));
211    }
212    #[test]
213    fn test_string_monoid_ext() {
214        let mut m = StringMonoidExt::new();
215        assert!(m.is_identity());
216        m.mappend("hello");
217        assert!(!m.is_identity());
218        m.mappend(" world");
219        assert_eq!(m.buffer, "hello world");
220    }
221    #[test]
222    fn test_substring_finder2() {
223        let finder = SubstringFinder2::new("ababab", "ab");
224        let naive = finder.find_all();
225        let kmp = finder.find_kmp();
226        assert_eq!(naive, kmp);
227        assert_eq!(naive, vec![0, 2, 4]);
228    }
229    #[test]
230    fn test_string_encoder_ext() {
231        let enc = StringEncoderExt::utf8();
232        assert!(enc.roundtrip("hello"));
233        assert!(enc.roundtrip(""));
234        let bytes = enc.encode("abc");
235        assert_eq!(bytes, b"abc");
236    }
237    #[test]
238    fn test_levenshtein_metric2() {
239        let m = LevenshteinMetric2::new();
240        assert!(m.identity_law("hello"));
241        assert!(m.symmetry_law("kitten", "sitting"));
242        assert_eq!(m.distance("abc", "abc"), 0);
243        let m2 = LevenshteinMetric2::with_max(2);
244        assert!(m2.within_threshold("abc", "abd"));
245        assert!(!m2.within_threshold("abc", "xyz"));
246    }
247    #[test]
248    fn test_rolling_hash_ext() {
249        let rh = RollingHashExt::new();
250        let positions = rh.find("ababab", "ab");
251        assert_eq!(positions, vec![0, 2, 4]);
252        assert_eq!(rh.hash_str("hello"), rh.hash_str("hello"));
253    }
254}