Merge: Reworked crypto.nit to introduce basic XOR attacks
[nit.git] / benchmarks / csv / scripts / csv_gen.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import csv
16
17 if args.length < 3 then
18 print "Usage ./csv_gen record_length record_nb out_filepath [--unicode]"
19 exit 1
20 end
21
22 var record_length = args[0].to_i
23 var record_nb = args[1].to_i
24 var outpath = args[2]
25 var unicode = false
26
27 if args.length == 4 then
28 if not args[3] == "--unicode" then
29 print "Usage ./csv_gen record_length record_nb [--unicode]"
30 exit 1
31 end
32 unicode = true
33 end
34
35 var ocsv = new CsvDocument
36 ocsv.eol = "\r\n"
37
38 var sep = ocsv.separator.to_s
39 var eol = ocsv.eol
40 var del = ocsv.delimiter.to_s
41
42 for i in [0 .. record_length[ do ocsv.header.add "Col{i}"
43
44 var c = if unicode then "รก" else "a"
45 for i in [0 .. record_nb[ do
46 var line = new Array[String].with_capacity(record_length)
47 for j in [0 .. record_length[ do
48 var add_sep = 100.rand > 70
49 var add_del = 100.rand > 70
50 var add_eol = 100.rand > 70
51 var ln = 10.rand
52 var s = c * ln
53 if add_sep then s = sep + s
54 if add_del then s += del
55 if add_eol then s += eol
56 line.add s
57 end
58 ocsv.records.add line
59 end
60
61 ocsv.write_to_file(outpath)