Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: courgette/third_party/bsdiff/qsufsort_unittest.cc

Issue 1948843002: [Courgette Experimental] Replace QSufSort with libdivsufsort Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and merge. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/third_party/bsdiff/qsufsort.h ('k') | courgette/third_party/divsufsort/LICENSE » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "courgette/third_party/bsdiff/qsufsort.h"
6
7 #include <stddef.h>
8
9 #include <algorithm>
10 #include <cstring>
11 #include <string>
12 #include <vector>
13
14 #include "base/macros.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 TEST(QSufSortTest, Sort) {
18 const char* test_cases[] = {
19 "",
20 "a",
21 "za",
22 "CACAO",
23 "banana",
24 "tobeornottobe",
25 "The quick brown fox jumps over the lazy dog.",
26 "elephantelephantelephantelephantelephant",
27 "-------------------------",
28 "011010011001011010010110011010010",
29 "3141592653589793238462643383279502884197169399375105",
30 "\xFF\xFE\xFF\xFE\xFD\x80\x30\x31\x32\x80\x30\xFF\x01\xAB\xCD",
31 };
32
33 for (size_t idx = 0; idx < arraysize(test_cases); ++idx) {
34 int len = static_cast<int>(::strlen(test_cases[idx]));
35 const unsigned char* s =
36 reinterpret_cast<const unsigned char*>(test_cases[idx]);
37
38 // Generate the suffix array as I.
39 std::vector<int> I(len + 1);
40 std::vector<int> V(len + 1);
41 courgette::qsuf::qsufsort<int*>(&I[0], &V[0], s, len);
42
43 // Expect that I[] is a permutation of [0, len].
44 std::vector<int> I_sorted(I);
45 std::sort(I_sorted.begin(), I_sorted.end());
46 for (int i = 0; i < len + 1; ++i)
47 EXPECT_EQ(i, I_sorted[i]);
48
49 // First string must be empty string.
50 EXPECT_EQ(len, I[0]);
51
52 // Expect that the |len + 1| suffixes are strictly ordered.
53 const unsigned char* end = s + len;
54 for (int i = 0; i < len; ++i) {
55 const unsigned char* suf1 = s + I[i];
56 const unsigned char* suf2 = s + I[i + 1];
57 bool is_less = std::lexicographical_compare(suf1, end, suf2, end);
58 EXPECT_TRUE(is_less);
59 }
60 }
61 }
OLDNEW
« no previous file with comments | « courgette/third_party/bsdiff/qsufsort.h ('k') | courgette/third_party/divsufsort/LICENSE » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698