@@ -27,53 +27,17 @@ class OrderedStringTestGenerator
2727 # beyond what actually gets indexed for ordering but doesn't bloat the test files too much.
2828 MAX_STRING_LENGTH = 200
2929
30- def run
31- create_orderise_string_test_cases
32- create_string_comparison_test_cases
33- end
34-
35- private
36-
37- def random_ascii_string
38- ( 0 ..rand ( MAX_STRING_LENGTH - 1 ) ) . map { rand ( ASCII_CHAR_CODE_MAX + 1 ) . chr } . join
39- end
40-
41- def index
42- id = SecureRandom . uuid
43- settings = {
44- "meta" => {
45- "$indexId" => id ,
46- "$indexName" => "titleSort" ,
47- "$prfKey" => SecureRandom . hex ( 16 ) ,
48- "$prpKey" => SecureRandom . hex ( 16 ) ,
49- } ,
50- "mapping" => {
51- "kind" => "range" ,
52- "field" => "title" ,
53- "fieldType" => "string" ,
54- }
55- }
56- schema_versions = { :first => 0 , :last => 0 , :searchable => true }
57-
58- CipherStash ::Index . generate ( id , settings , schema_versions )
59- end
60-
61- def write_cases_to_file ( filename , test_cases )
62- File . write ( filename , JSON . pretty_generate ( test_cases ) )
63- puts "Created ./" + filename
64- end
65-
66- def create_orderise_string_test_cases
30+ def generate_orderise_string_test_cases
6731 orderise_string_cases = ( 0 ..( NUM_TEST_CASES - 1 ) ) . map do
6832 str = random_ascii_string
6933 output = index . __send__ :orderise_string , str
7034 { input : str , output : output }
7135 end
7236
73- write_cases_to_file ( "orderise_string_test_cases.json" , orderise_string_cases )
37+ puts JSON . pretty_generate ( orderise_string_cases )
7438 end
7539
76- def create_string_comparison_test_cases
40+ def generate_string_comparison_test_cases
7741 string_comparison_cases = ( 0 ..( NUM_TEST_CASES - 1 ) ) . map do
7842 str_a = random_ascii_string
7943 terms_a = index . __send__ :orderise_string , str_a
@@ -93,7 +57,33 @@ def create_string_comparison_test_cases
9357 { input : [ str_a , str_b ] , output : output }
9458 end
9559
96- write_cases_to_file ( "string_comparison_test_cases.json" , string_comparison_cases )
60+ puts JSON . pretty_generate ( string_comparison_cases )
61+ end
62+
63+ private
64+
65+ def random_ascii_string
66+ ( 0 ..rand ( MAX_STRING_LENGTH - 1 ) ) . map { rand ( ASCII_CHAR_CODE_MAX + 1 ) . chr } . join
67+ end
68+
69+ def index
70+ id = SecureRandom . uuid
71+ settings = {
72+ "meta" => {
73+ "$indexId" => id ,
74+ "$indexName" => "titleSort" ,
75+ "$prfKey" => SecureRandom . hex ( 16 ) ,
76+ "$prpKey" => SecureRandom . hex ( 16 ) ,
77+ } ,
78+ "mapping" => {
79+ "kind" => "range" ,
80+ "field" => "title" ,
81+ "fieldType" => "string" ,
82+ }
83+ }
84+ schema_versions = { :first => 0 , :last => 0 , :searchable => true }
85+
86+ CipherStash ::Index . generate ( id , settings , schema_versions )
9787 end
9888 end
9989 end
0 commit comments