gettc 1.8 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13ea9a48db98416575bd26b1280e0b50e00813fd
4
- data.tar.gz: fd1bedf6f9f2ccef304249223ffec8b31ac87ce3
3
+ metadata.gz: b8f0620456e7f47a3b78dac16f5340db69b2708e
4
+ data.tar.gz: 9d58a132c8a69a0ead8997ba48fea763bff87d4f
5
5
  SHA512:
6
- metadata.gz: 6fa57ef95644085a280927ec69edcc6fedec7e65b875c998a89c3bcbf8bbf6a757e99dca0506869b9fc48723906767a487a739de65a9d671a378a850d7888b47
7
- data.tar.gz: deadbb5bb05c3b74c1a709f9303992c2182a46fa4cf825f5c747188a2bd31a67123c78de8557d1451fa98c0bbb7ee7e412f628b4058f6b13485ee624c7b8d0b3
6
+ metadata.gz: 5a93b2e574f63014b36b17c9d26386f36294db624833d9b88cd47549c3376b7739b0caf98698ba948bc2ab79bcfb10bef6babb8a715aaaf4150fe66b4603bec9
7
+ data.tar.gz: 6d2316fc246ac269ead57fa88448f3a8a8a1013cef1bb9c5c033ced8c414507859f136d55a1ad56c66b7825f0f7a767ad831cf6cf6fc3c1b10c174ed804e5e64
data/bin/gettc CHANGED
@@ -75,7 +75,7 @@ gettc reset: Bring all settings to default state.
75
75
  prob = parser.parse html
76
76
  puts "Done"
77
77
 
78
- print "Generating problem diectory for #{prob.name} ... "
78
+ print "Generating problem directory for #{prob.name} ... "
79
79
  generator.generate prob
80
80
  puts "Done"
81
81
  rescue TemplateError => terr
data/core/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gettc
2
- VERSION = "1.8"
2
+ VERSION = "1.8.1"
3
3
  end
data/dist/config.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  username: gettc
2
2
  password: algorithm
3
- version: 1.7.5.2
3
+ version: 1.8.1
@@ -108,12 +108,12 @@ namespace TopCoder {
108
108
  }
109
109
 
110
110
  void read(std::istream &is, char &c) {
111
- _expect(is, '\'');
112
- is.get(c);
113
- if (c == '\'') {
114
- c = 0;
115
- } else {
111
+ _spaces(is); char ch; is.get(ch);
112
+ if (ch == '\'') {
113
+ is.get(c);
116
114
  _expect(is, '\'');
115
+ } else {
116
+ c = ch;
117
117
  }
118
118
  }
119
119
 
@@ -1,3 +1,7 @@
1
+ // I hope to migrate this codebase to this style soon, to avoid the error
2
+ // checking madness: http://blog.golang.org/errors-are-values. However, it
3
+ // will break compatibility so I'll wait for a timely chance.
4
+
1
5
  package topcoder
2
6
 
3
7
  import (
@@ -38,4 +42,4 @@ func (me ErrExpect) Error() string {
38
42
 
39
43
  func NewErrExpect(r io.Reader, what string) ErrExpect {
40
44
  return ErrExpect(fmt.Sprintf("Expect %s at <%s>", what, rest(r)))
41
- }
45
+ }
@@ -12,8 +12,6 @@ import (
12
12
  func spaces(br *bufio.Reader) error {
13
13
  for {
14
14
  switch b, err := br.ReadByte(); {
15
- case err == io.EOF:
16
- return nil
17
15
  case err != nil:
18
16
  return err
19
17
  case !unicode.IsSpace(rune(b)):
@@ -26,8 +24,6 @@ func spaces(br *bufio.Reader) error {
26
24
 
27
25
  func genericExpect(br *bufio.Reader, what string, predicate func(byte) bool) error {
28
26
  switch b, err := br.ReadByte(); {
29
- case err == io.EOF:
30
- return io.ErrUnexpectedEOF
31
27
  case err != nil:
32
28
  return err
33
29
  case !predicate(b):
@@ -64,19 +60,20 @@ func readChar(br *bufio.Reader, pChar *byte) error {
64
60
  if err = spaces(br); err != nil {
65
61
  return err
66
62
  }
67
- if err = expect(br, '\''); err != nil {
68
- return err
69
- }
70
63
  switch b, err = br.ReadByte(); {
71
- case err == io.EOF:
72
- return io.ErrUnexpectedEOF
73
64
  case err != nil:
74
65
  return err
66
+ case b == '\'':
67
+ switch ret, errInside := br.ReadByte(); {
68
+ case errInside != nil:
69
+ return errInside
70
+ default:
71
+ *pChar = ret
72
+ return expect(br, '\'')
73
+ }
74
+ default:
75
+ *pChar = b
75
76
  }
76
- if err = expect(br, '\''); err != nil {
77
- return err
78
- }
79
- *pChar = b
80
77
  return nil
81
78
  }
82
79
 
@@ -124,8 +121,6 @@ func readString(br *bufio.Reader, pString *string) error {
124
121
  w := bytes.NewBufferString("")
125
122
  for {
126
123
  switch b, err = br.ReadByte(); {
127
- case err == io.EOF:
128
- return io.ErrUnexpectedEOF
129
124
  case err != nil:
130
125
  return err
131
126
  case b != '"':
@@ -157,8 +157,9 @@ func TestReadByte(t *testing.T) {
157
157
  var (
158
158
  xs = []aTest {
159
159
  aTest{"'H'ello", 'H', true},
160
- aTest{"\n\t 'H'23", 'H', true},
161
- aTest{"Hello", 'H', false},
160
+ aTest{"\n\t 'A'23", 'A', true},
161
+ aTest{"Bello", 'B', true},
162
+ aTest{"'C", 'C', false},
162
163
  }
163
164
  got byte
164
165
  )
@@ -320,14 +321,15 @@ func TestReadAll(t *testing.T) {
320
321
  age int
321
322
  gender byte
322
323
  average float32
324
+ grade byte
323
325
  courses []string
324
326
  grades [][]float64
325
327
  )
326
- in := "\"Joe\", 20, 'M', 7.5, [\"Math\", \"Computer \"Science\"\"], [[7, 8], []]"
328
+ in := "\"Joe\", 20, 'M', 7.5, C, [\"Math\", \"Computer \"Science\"\"], [[7, 8], []]"
327
329
  br := newReader(in)
328
330
  f := fmt.Sprintf("Read(%v)", in)
329
- Read(br, &name, &age, &gender, &average, &courses, &grades)
330
- if name != "Joe" || age != 20 || average != 7.5 || gender != 'M' ||
331
+ Read(br, &name, &age, &gender, &average, &grade, &courses, &grades)
332
+ if name != "Joe" || age != 20 || average != 7.5 || gender != 'M' || grade != 'C' ||
331
333
  !reflect.DeepEqual(courses, []string{"Math", "Computer \"Science\""}) ||
332
334
  !reflect.DeepEqual(grades, [][]float64{{7, 8}, {}}) {
333
335
  t.Errorf(f + " produces (%q, %d, &q, %f, %v, %v)", name, age, gender, average, courses, grades)
@@ -25,13 +25,17 @@ next = do
25
25
  return ()
26
26
 
27
27
 
28
- parseChar :: Parser Char
29
- parseChar = do
28
+ parseQuotedChar :: Parser Char
29
+ parseQuotedChar = do
30
30
  char '\''
31
31
  ret <- anyChar
32
32
  char '\''
33
33
  return ret
34
34
 
35
+ parseChar :: Parser Char
36
+ parseChar = parseQuotedChar <|> anyChar
37
+
38
+
35
39
  parseBool :: Parser Bool
36
40
  parseBool = do
37
41
  s <- many1 letter
@@ -97,4 +101,4 @@ parseList parser = do
97
101
  spaces >> char '[' >> spaces
98
102
  xs <- parseElems parser
99
103
  spaces >> char ']'
100
- return xs
104
+ return xs
Binary file
@@ -101,10 +101,14 @@ class ReaderInternal(object):
101
101
 
102
102
  def next_char(self):
103
103
  self.spaces()
104
- self.expect("'")
105
104
  c = self.token()
105
+ if c == "'":
106
+ self.pos += 1
107
+ ret = self.token()
108
+ self.pos += 1
109
+ self.expect("'")
110
+ return ret
106
111
  self.pos += 1
107
- self.expect("'")
108
112
  return c
109
113
 
110
114
  def next_boolean(self):
@@ -157,4 +161,4 @@ class ReaderInternal(object):
157
161
  return result
158
162
  result.append(self.next(elem_type))
159
163
  self.next_elems(elem_type, result)
160
- return result
164
+ return result
@@ -1,173 +1,178 @@
1
- require "fileutils"
2
- require "logger"
3
-
4
- class SysUtil
5
- def self.with_dir dir
6
- saved = FileUtils.pwd
7
- FileUtils.chdir dir
8
- yield
9
- FileUtils.chdir saved
10
- end
11
- end
12
-
13
- class StopWatch
14
- def self.measure
15
- before = Time.now
16
- yield
17
- after = Time.now
18
- return ((after - before) * 1000).round
19
- end
20
- end
21
-
22
- class GettcRunner
23
- def initialize mode, solver, data_d, output_d
24
- @verbose = (mode == "verbose")
25
- @solver = solver
26
- @data_d = data_d
27
- @output_d = output_d
28
-
29
- @dir = File.dirname __FILE__
30
-
31
- FileUtils.mkdir_p @output_d
32
-
33
- @log = Logger.new STDOUT
34
- @log.formatter = proc do |severity, datetime, progname, message|
35
- message
36
- end
37
- @log.level = Logger::INFO
38
- if @verbose
39
- @log.level = Logger::DEBUG
40
- end
41
- end
42
-
43
- def compile_checker
44
- puts "[gettc] Compile checker"
45
- @checker = File.join @dir, "../build/check"
46
- unless File.exists? @checker
47
- checker_src = File.join @dir, "../util/check"
48
- SysUtil::with_dir checker_src do
49
- system "make"
50
- end
51
- end
52
- end
53
-
54
- def populate_filenames n
55
- input = File.join @data_d, "#{n}.in"
56
- expected = File.join @data_d, "#{n}.out"
57
- received = File.join @output_d, "#{n}.out"
58
- return input, expected, received
59
- end
60
-
61
- def print_file_content label, filename
62
- print " #{label}: <"
63
- print File.read(filename)
64
- puts ">"
65
- end
66
-
67
- def print_case n
68
- input, expected, received = populate_filenames n
69
- print_file_content "Input", input
70
- print_file_content "Expected", expected
71
- print_file_content "Received", received
72
- end
73
-
74
- def run_case n
75
- input, expected, received = populate_filenames n
76
-
77
- @log.debug "Case #{n} ... "
78
- ret = true
79
-
80
- elapsed = StopWatch::measure do
81
- ret = system "#{@solver} #{input} #{received}"
82
- end
83
- @elapsed << elapsed
84
- @log.debug "#{elapsed}ms "
85
-
86
- if ret != true
87
- @errors << n
88
- @log.debug "Error\n"
89
- else
90
- system "#{@checker} #{expected} #{received}"
91
- ret = $?.exitstatus
92
- case ret
93
- when 0
94
- @log.debug "Passed\n"
95
- when 1
96
- @log.debug "Failed\n"
97
- @failures << n
98
- print_case n if @verbose
99
- when 2
100
- @log.debug "Error\n"
101
- @errors << n
102
- end
103
- end
104
- end
105
-
106
- def run_all_cases
107
- puts "[gettc] Run test cases"
108
-
109
- inputs = Dir.glob "#{@data_d}/*.in"
110
-
111
- @total = inputs.size
112
- @elapsed = Array.new
113
- @failures = Array.new
114
- @errors = Array.new
115
-
116
- @total.times do |n|
117
- run_case n
118
- end
119
- end
120
-
121
- def print_array label, arr
122
- if arr.size > 0
123
- print "#{label}: "
124
- puts arr.join(", ")
125
- end
126
- end
127
-
128
- def summarize
129
- puts "[gettc] Summary"
130
- puts "#{@total} cases checked, #{@failures.size} failures, #{@errors.size} errors"
131
- print_array "Failures", @failures
132
- print_array " Errors", @errors
133
-
134
- if @total > 0
135
- sum = @elapsed.inject 0, :+
136
- avg = sum / @elapsed.size
137
- puts " Total time taken: #{sum} ms"
138
- puts " Average time taken: #{avg} ms"
139
-
140
- i, j = 0, 0
141
- @elapsed.size.times do |k|
142
- if @elapsed[k] > j
143
- i, j = k, @elapsed[k]
144
- end
145
- end
146
- puts " Slowest running case: #{j} ms (case #{i})"
147
- end
148
- end
149
-
150
- def print_failures
151
- if @failures.empty? || @verbose
152
- return
153
- end
154
- puts "Here are a few failed case for your debugging purposes"
155
-
156
- n = [5, @failures.size].min
157
- n.times do |i|
158
- j = @failures[i]
159
- puts "Case #{j}:"
160
- print_case j
161
- end
162
- end
163
-
164
- def run
165
- compile_checker
166
- run_all_cases
167
- print_failures
168
- summarize
169
- end
170
- end
171
-
172
- runner = GettcRunner.new ARGV[0], ARGV[1], ARGV[2], ARGV[3]
173
- runner.run
1
+ require "fileutils"
2
+ require "logger"
3
+
4
+ class SysUtil
5
+ def self.with_dir dir
6
+ saved = FileUtils.pwd
7
+ FileUtils.chdir dir
8
+ yield
9
+ FileUtils.chdir saved
10
+ end
11
+ end
12
+
13
+ class StopWatch
14
+ def self.measure
15
+ before = Time.now
16
+ yield
17
+ after = Time.now
18
+ return ((after - before) * 1000).round
19
+ end
20
+ end
21
+
22
+ class GettcRunner
23
+ def initialize mode, solver, data_d, output_d
24
+ @verbose = (mode == "verbose")
25
+ @solver = solver
26
+ @data_d = data_d
27
+ @output_d = output_d
28
+
29
+ @dir = File.dirname __FILE__
30
+
31
+ FileUtils.mkdir_p @output_d
32
+
33
+ @log = Logger.new STDOUT
34
+ @log.formatter = proc do |severity, datetime, progname, message|
35
+ message
36
+ end
37
+ @log.level = Logger::INFO
38
+ if @verbose
39
+ @log.level = Logger::DEBUG
40
+ end
41
+ end
42
+
43
+ def compile_checker
44
+ puts "[gettc] Compile checker"
45
+ @checker = File.join @dir, "../build/check"
46
+ unless File.exists? @checker
47
+ checker_src = File.join @dir, "../util/check"
48
+ SysUtil::with_dir checker_src do
49
+ system "make"
50
+ end
51
+ end
52
+ end
53
+
54
+ def populate_filenames n
55
+ input = File.join @data_d, "#{n}.in"
56
+ expected = File.join @data_d, "#{n}.out"
57
+ received = File.join @output_d, "#{n}.out"
58
+ return input, expected, received
59
+ end
60
+
61
+ def print_file_content label, filename
62
+ print " #{label}: <"
63
+ print File.read(filename)
64
+ puts ">"
65
+ end
66
+
67
+ def print_case n
68
+ input, expected, received = populate_filenames n
69
+ print_file_content "Input", input
70
+ print_file_content "Expected", expected
71
+ print_file_content "Received", received
72
+ end
73
+
74
+ def run_case n
75
+ input, expected, received = populate_filenames n
76
+
77
+ @log.debug "Case #{n} ... "
78
+ ret = true
79
+
80
+ elapsed = StopWatch::measure do
81
+ ret = system "#{@solver} #{input} #{received}"
82
+ end
83
+ @elapsed << elapsed
84
+ @log.debug "#{elapsed}ms "
85
+
86
+ if ret != true
87
+ @errors << n
88
+ @log.debug "Error (cannot execute solver)\n"
89
+ else
90
+ ret = system "#{@checker} #{expected} #{received}"
91
+ if ret != true
92
+ @errors << n
93
+ @log.debug "Error (cannot execute checker)\n"
94
+ else
95
+ ret = $?.exitstatus
96
+ case ret
97
+ when 0
98
+ @log.debug "Passed\n"
99
+ when 1
100
+ @log.debug "Failed\n"
101
+ @failures << n
102
+ print_case n if @verbose
103
+ when 2
104
+ @log.debug "Error (checker reported error)\n"
105
+ @errors << n
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ def run_all_cases
112
+ puts "[gettc] Run test cases"
113
+
114
+ inputs = Dir.glob "#{@data_d}/*.in"
115
+
116
+ @total = inputs.size
117
+ @elapsed = Array.new
118
+ @failures = Array.new
119
+ @errors = Array.new
120
+
121
+ @total.times do |n|
122
+ run_case n
123
+ end
124
+ end
125
+
126
+ def print_array label, arr
127
+ if arr.size > 0
128
+ print "#{label}: "
129
+ puts arr.join(", ")
130
+ end
131
+ end
132
+
133
+ def summarize
134
+ puts "[gettc] Summary"
135
+ puts "#{@total} cases checked, #{@failures.size} failures, #{@errors.size} errors"
136
+ print_array "Failures", @failures
137
+ print_array "Errors", @errors
138
+
139
+ if @total > 0
140
+ sum = @elapsed.inject 0, :+
141
+ avg = sum / @elapsed.size
142
+ puts " Total time taken: #{sum} ms"
143
+ puts " Average time taken: #{avg} ms"
144
+
145
+ i, j = 0, 0
146
+ @elapsed.size.times do |k|
147
+ if @elapsed[k] > j
148
+ i, j = k, @elapsed[k]
149
+ end
150
+ end
151
+ puts " Slowest running case: #{j} ms (case #{i})"
152
+ end
153
+ end
154
+
155
+ def print_failures
156
+ if @failures.empty? || @verbose
157
+ return
158
+ end
159
+ puts "Here are a few failed case for your debugging purposes"
160
+
161
+ n = [5, @failures.size].min
162
+ n.times do |i|
163
+ j = @failures[i]
164
+ puts "Case #{j}:"
165
+ print_case j
166
+ end
167
+ end
168
+
169
+ def run
170
+ compile_checker
171
+ run_all_cases
172
+ print_failures
173
+ summarize
174
+ end
175
+ end
176
+
177
+ runner = GettcRunner.new ARGV[0], ARGV[1], ARGV[2], ARGV[3]
178
+ runner.run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettc
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot
@@ -78,13 +78,13 @@ files:
78
78
  - dist/include/java/engine.rb
79
79
  - dist/include/python/engine.rb
80
80
  - dist/include/python/topcoder/__init__.py
81
- - dist/include/python/topcoder/__pycache__/__init__.cpython-32.pyc
82
- - dist/include/python/topcoder/__pycache__/errors.cpython-32.pyc
83
- - dist/include/python/topcoder/__pycache__/reader.cpython-32.pyc
84
- - dist/include/python/topcoder/__pycache__/writer.cpython-32.pyc
81
+ - dist/include/python/topcoder/__init__.pyc
85
82
  - dist/include/python/topcoder/errors.py
83
+ - dist/include/python/topcoder/errors.pyc
86
84
  - dist/include/python/topcoder/reader.py
85
+ - dist/include/python/topcoder/reader.pyc
87
86
  - dist/include/python/topcoder/writer.py
87
+ - dist/include/python/topcoder/writer.pyc
88
88
  - dist/template/bin/runner.rb
89
89
  - dist/template/bin/runner.sh
90
90
  - dist/template/data/demo/{examples_d}