int test() { std::string s2 = "yabadabadoo"; SuffixArray sa2(s2); print_ranks(s2, sa2); print_suffix_array(s2, sa2); vpii_t slcp; sa2.lcp_across_sets(4, slcp); for (size_t i = 0; i < slcp.size(); ++i) { printf("slcp[%d] = (%d, %d)\n", i, slcp[i].INDEX, slcp[i].LENGTH); } print_pairwise_lcp(s2, sa2); // return 0; SuffixArray sa1("banana"); print_ranks("banana", sa1); SuffixArray sa3("mississippi"); print_ranks("mississippi", sa3); std::string s4 = "Regular expressions, or just regexes, are at the core of Perl's text processing, and certainly are one of the features that made Perl so popular. All Perl programmers pass through a stage where they try to program everything as regexes, and when that's not challenging enough, everything as a single regex. Perl's regexes have many more features than I can, or want, to present here, so I include those advanced features I find most useful and expect other Perl programmers to know about without referring to perlre, the documentation page for regexes."; SuffixArray sa4(s4); print_ranks(s4, sa4); print_suffix_array(s4, sa4); cout<<endl; print_pairwise_lcp(s4, sa4); return 0; }
void make_sure_ok(string s) { // s = s + "~"; suffix_array sa1(s); naive_suffix_array sa2(s); // for (int i = 0; i < size(s); i++) { // cout << s.substr(sa1.idx[i]) << endl; // } // cout << endl; // for (int i = 0; i < size(s); i++) { // cout << s.substr(sa2.idx[i]) << endl; // } // cout << endl; for (int i = 0; i < size(s); i++) { assert_equal(sa1.idx[i], sa2.idx[i]); if (sa1.idx[i] != sa2.idx[i]) { cout << s << endl; } } }
void test5(){ SharedArry<int> sa(new int[10]); SharedArry<int> sa1(sa); sa[0] = 10; SharedArry<int> sa2(new int[10]); SharedArry<int> sa3(sa2); sa2 = sa; }
// ============================================================================ // Address Test // void runAddressTest() { TraceL << "Starting" << endl; Address sa1("192.168.1.100", 100); assert(sa1.host() == "192.168.1.100"); assert(sa1.port() == 100); Address sa2("192.168.1.100", "100"); assert(sa2.host() == "192.168.1.100"); assert(sa2.port() == 100); Address sa3("192.168.1.100", "ftp"); assert(sa3.host() == "192.168.1.100"); assert(sa3.port() == 21); Address sa7("192.168.2.120:88"); assert(sa7.host() == "192.168.2.120"); assert(sa7.port() == 88); Address sa8("[192.168.2.120]:88"); assert(sa8.host() == "192.168.2.120"); assert(sa8.port() == 88); try { Address sa3("192.168.1.100", "f00bar"); assert(0 && "bad service name - must throw"); } catch (std::exception&) {} try { Address sa6("192.168.2.120", "80000"); assert(0 && "invalid port - must throw"); } catch (std::exception&) {} try { Address sa5("192.168.2.260", 80); assert(0 && "invalid address - must throw"); } catch (std::exception&) {} try { Address sa9("[192.168.2.260:", 88); assert(0 && "invalid address - must throw"); } catch (std::exception&) {} try { Address sa9("[192.168.2.260]"); assert(0 && "invalid address - must throw"); } catch (std::exception&) {} }
void tst_QVarLengthArray::oldTests() { { QVarLengthArray<int, 256> sa(128); QVERIFY(sa.data() == &sa[0]); sa[0] = 0xfee; sa[10] = 0xff; QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); sa.resize(512); QVERIFY(sa.data() == &sa[0]); QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); QVERIFY(sa.at(0) == 0xfee); QVERIFY(sa.at(10) == 0xff); QVERIFY(sa.value(0) == 0xfee); QVERIFY(sa.value(10) == 0xff); QVERIFY(sa.value(1000) == 0); QVERIFY(sa.value(1000, 12) == 12); QVERIFY(sa.size() == 512); sa.reserve(1024); QVERIFY(sa.capacity() == 1024); QVERIFY(sa.size() == 512); } { QVarLengthArray<QString> sa(10); sa[0] = "Hello"; sa[9] = "World"; QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.reserve(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.resize(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); } { int arr[2] = {1, 2}; QVarLengthArray<int> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], 1); QCOMPARE(sa[11], 2); } { QString arr[2] = { QString("hello"), QString("world") }; QVarLengthArray<QString> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], QString("hello")); QCOMPARE(sa[11], QString("world")); QCOMPARE(sa.at(10), QString("hello")); QCOMPARE(sa.at(11), QString("world")); QCOMPARE(sa.value(10), QString("hello")); QCOMPARE(sa.value(11), QString("world")); QCOMPARE(sa.value(10000), QString()); QCOMPARE(sa.value(1212112, QString("none")), QString("none")); QCOMPARE(sa.value(-12, QString("neg")), QString("neg")); sa.append(arr, 1); QCOMPARE(sa.size(), 13); QCOMPARE(sa[12], QString("hello")); sa.append(arr, 0); QCOMPARE(sa.size(), 13); } { // assignment operator and copy constructor QVarLengthArray<int> sa(10); sa[5] = 5; QVarLengthArray<int> sa2(10); sa2[5] = 6; sa2 = sa; QCOMPARE(sa2[5], 5); QVarLengthArray<int> sa3(sa); QCOMPARE(sa3[5], 5); } QSKIP("This test causes the machine to crash when allocating too much memory.", SkipSingle); { QVarLengthArray<Foo> a; const int N = 0x7fffffff / sizeof(Foo); const int Prealloc = a.capacity(); const Foo *data0 = a.constData(); a.resize(N); if (a.size() == N) { QVERIFY(a.capacity() >= N); QCOMPARE(fooCtor, N); QCOMPARE(fooDtor, 0); for (int i = 0; i < N; i += 35000) a[i] = Foo(); } else { // this is the case we're actually testing QCOMPARE(a.size(), 0); QCOMPARE(a.capacity(), Prealloc); QCOMPARE(a.constData(), data0); QCOMPARE(fooCtor, 0); QCOMPARE(fooDtor, 0); a.resize(5); QCOMPARE(a.size(), 5); QCOMPARE(a.capacity(), Prealloc); QCOMPARE(a.constData(), data0); QCOMPARE(fooCtor, 5); QCOMPARE(fooDtor, 0); a.resize(Prealloc + 1); QCOMPARE(a.size(), Prealloc + 1); QVERIFY(a.capacity() >= Prealloc + 1); QVERIFY(a.constData() != data0); QCOMPARE(fooCtor, Prealloc + 6); QCOMPARE(fooDtor, 5); const Foo *data1 = a.constData(); a.resize(0x10000000); QCOMPARE(a.size(), 0); QVERIFY(a.capacity() >= Prealloc + 1); QVERIFY(a.constData() == data1); QCOMPARE(fooCtor, Prealloc + 6); QCOMPARE(fooDtor, Prealloc + 6); } } }
void Definition::GetAsNumber(Number<T>& n, StringMapW<T>* n2n) { CStringW str = m_value; str.Replace(L" ", L""); n.value = 0; n.unit = m_unit; n.sign = 0; if(n2n) { if(m_status == node) throw Exception(_T("expected value type")); if(StringMapW<T>::CPair* p = n2n->Lookup(str)) { n.value = p->m_value; return; } } if(m_status != number) throw Exception(_T("expected number")); n.sign = str.Find('+') == 0 ? 1 : str.Find('-') == 0 ? -1 : 0; str.TrimLeft(L"+-"); if(str.Find(L"0x") == 0) { if(n.sign) throw Exception(_T("hex values must be unsigned")); n.value = (T)wcstoul(str.Mid(2), NULL, 16); } else { CStringW num_string = m_value + m_unit; if(m_num_string != num_string) { Split sa(':', str); Split sa2('.', sa ? sa[sa-1] : L""); if(sa == 0 || sa2 == 0 || sa2 > 2) throw Exception(_T("invalid number")); float f = 0; for(size_t i = 0; i < sa; i++) { f *= 60; f += wcstoul(sa[i], NULL, 10); } if(sa2 > 1) f += (float)wcstoul(sa2[1], NULL, 10) / pow((float)10, sa2[1].GetLength()); if(n.unit == L"ms") { f /= 1000; n.unit = L"s"; } else if(n.unit == L"m") { f *= 60; n.unit = L"s"; } else if(n.unit == L"h") { f *= 3600; n.unit = L"s"; } m_num.value = f; m_num.unit = n.unit; m_num_string = num_string; n.value = (T)f; } else { n.value = (T)m_num.value; n.unit = m_num.unit; } if(n.sign) n.value *= n.sign; } }
void tst_QVarLengthArray::oldTests() { { QVarLengthArray<int, 256> sa(128); QVERIFY(sa.data() == &sa[0]); sa[0] = 0xfee; sa[10] = 0xff; QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); sa.resize(512); QVERIFY(sa.data() == &sa[0]); QVERIFY(sa[0] == 0xfee); QVERIFY(sa[10] == 0xff); QVERIFY(sa.at(0) == 0xfee); QVERIFY(sa.at(10) == 0xff); QVERIFY(sa.value(0) == 0xfee); QVERIFY(sa.value(10) == 0xff); QVERIFY(sa.value(1000) == 0); QVERIFY(sa.value(1000, 12) == 12); QVERIFY(sa.size() == 512); sa.reserve(1024); QVERIFY(sa.capacity() == 1024); QVERIFY(sa.size() == 512); } { QVarLengthArray<QString> sa(10); sa[0] = "Hello"; sa[9] = "World"; QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.reserve(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); sa.resize(512); QVERIFY(*sa.data() == "Hello"); QVERIFY(sa[9] == "World"); } { int arr[2] = {1, 2}; QVarLengthArray<int> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], 1); QCOMPARE(sa[11], 2); } { QString arr[2] = { QString("hello"), QString("world") }; QVarLengthArray<QString> sa(10); QCOMPARE(sa.size(), 10); sa.append(arr, 2); QCOMPARE(sa.size(), 12); QCOMPARE(sa[10], QString("hello")); QCOMPARE(sa[11], QString("world")); QCOMPARE(sa.at(10), QString("hello")); QCOMPARE(sa.at(11), QString("world")); QCOMPARE(sa.value(10), QString("hello")); QCOMPARE(sa.value(11), QString("world")); QCOMPARE(sa.value(10000), QString()); QCOMPARE(sa.value(1212112, QString("none")), QString("none")); QCOMPARE(sa.value(-12, QString("neg")), QString("neg")); sa.append(arr, 1); QCOMPARE(sa.size(), 13); QCOMPARE(sa[12], QString("hello")); sa.append(arr, 0); QCOMPARE(sa.size(), 13); } { // assignment operator and copy constructor QVarLengthArray<int> sa(10); sa[5] = 5; QVarLengthArray<int> sa2(10); sa2[5] = 6; sa2 = sa; QCOMPARE(sa2[5], 5); QVarLengthArray<int> sa3(sa); QCOMPARE(sa3[5], 5); } }