MCPcopy Create free account
hub / github.com/Singular/Singular / Main

Function Main

ppcc/adlib/test4.cc:41–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41void Main() {
42 StrArr *arr = new StrArr();
43 Str *collect = new Str();
44
45 arr->add(S("x"))->add(S("y"))->add(S("abc"));
46 arr = arr->clone();
47 for (StrArr::Each iter(arr); iter; ++iter) {
48 collect->add(*iter)->add(iter->c_str());
49 }
50 for (Str::Each iter(arr->last()->clone()); iter; ++iter) {
51 collect->add(*iter);
52 }
53 Check(collect->eq("xxyyabcabcabc"), "array/string iteration");
54 collect = new Str();
55 arr = arr->map<Str *>(capitalize);
56 for (StrArr::Each iter(arr); iter; ++iter) {
57 collect->add(*iter);
58 collect->add(iter->c_str());
59 }
60 for (Str::Each iter(arr->last()->clone()); iter; ++iter) {
61 collect->add(*iter);
62 }
63 Check(collect->eq("XXYYAbcAbcAbc"), "array map");
64 Arr<Int> *intarr = new Arr<Int>();
65 for (int i = 1; i <= 10; i++) {
66 intarr->add(i);
67 }
68 Check(intarr->fold(0, add) == 10 * 11 / 2, "array folding");
69 Check(intarr->filter(even)->len() == 5, "array filtering");
70 intarr = new Arr<Int>();
71 for (Word i = 0, v = 1; i < 100000; i++) {
72 intarr->add((Int) v);
73 v = (5 * v + 1) & 0xffffff;
74 }
75 intarr = intarr->sort(IntCmp);
76 int mismatch = 0;
77 for (Int i = 1; i < intarr->len(); i++) {
78 if (intarr->at(i - 1) >= intarr->at(i))
79 mismatch++;
80 }
81 Check(mismatch == 0, "sorting arrays");
82 StrSet *set = new StrSet();
83 set->add(S("x"));
84 set->add(S("y"));
85 set->add(S("z"));
86 set->add(S("x"));
87 StrSet *set2 = new StrSet();
88 set2->add(S("u"));
89 set2->add(S("y"));
90 set2->add(S("z"));
91
92 StrSet *uset = set->union_with(set2);
93 StrSet *iset = set->intersect_with(set2);
94 StrSet *dset = set->diff_with(set2);
95 Check(uset->count() == 4, "set union");
96 Check(iset->count() == 2, "set intersection");
97 Check(dset->count() == 1, "set difference");
98 uset = set->clone();

Callers

nothing calls this directly

Calls 15

CheckFunction · 0.85
AFunction · 0.85
c_strMethod · 0.80
lastMethod · 0.80
get_or_addMethod · 0.80
SFunction · 0.70
FFunction · 0.70
addMethod · 0.45
cloneMethod · 0.45
eqMethod · 0.45
foldMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected