gettc 1.7.5.2 → 1.8

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: 13552ba943e6d584a550948f87a8b47e3f1ba49e
4
- data.tar.gz: 0297b4be2390337b495752a2ffc7fefedd4f57e6
3
+ metadata.gz: 13ea9a48db98416575bd26b1280e0b50e00813fd
4
+ data.tar.gz: fd1bedf6f9f2ccef304249223ffec8b31ac87ce3
5
5
  SHA512:
6
- metadata.gz: 854da9c3e7f5d326986e79bcadc72ec5eb7326fa311909bcdde2428df04a47f74fcf431bbc01b072d8d7d03e75b0819242d0140dc386269ca52653fcbf332f62
7
- data.tar.gz: 2e4fe3a26b32b10a3744c02d1e690eb21b1dcb810a309930abe78e63248fbe4492a1939957a5fd634180b6eb94b349de73fd3ca8b36af236b0b6239e23daabe1
6
+ metadata.gz: 6fa57ef95644085a280927ec69edcc6fedec7e65b875c998a89c3bcbf8bbf6a757e99dca0506869b9fc48723906767a487a739de65a9d671a378a850d7888b47
7
+ data.tar.gz: deadbb5bb05c3b74c1a709f9303992c2182a46fa4cf825f5c747188a2bd31a67123c78de8557d1451fa98c0bbb7ee7e412f628b4058f6b13485ee624c7b8d0b3
data/bin/gettc CHANGED
@@ -46,7 +46,7 @@ def main
46
46
  usage = <<-eos.strip
47
47
  gettc <id>: Generate a solution for the TopCoder problem with that ID, eg 11138.
48
48
  gettc version: Print version string.
49
- gettc reset: Force a reset of the contents in GETTC_HOME.
49
+ gettc reset: Bring all settings to default state.
50
50
  eos
51
51
  if ARGV.empty?
52
52
  puts usage
@@ -1,3 +1,3 @@
1
1
  module Gettc
2
- VERSION = "1.7.5.2"
2
+ VERSION = "1.8"
3
3
  end
@@ -0,0 +1,173 @@
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
@@ -5,55 +5,62 @@ mode="$1"
5
5
  solver="$2"
6
6
  data_d="$3"
7
7
  output_d="$4"
8
- ostream=/dev/null
9
8
 
10
9
  command_exists () {
11
10
  type "$1" > /dev/null 2>&1 ;
12
11
  }
13
12
 
14
13
  timeit () {
15
- if command_exists /usr/bin/time ; then
16
- /usr/bin/time -o /dev/null echo "Testing availability of the time command" > /dev/null 2>&1
17
- if [ $? -eq 0 ]; then
18
- /usr/bin/time -o $ostream "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
19
- return
20
- elif [ $mode = 'verbose' ]; then
21
- /usr/bin/time "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
22
- return
23
- fi
24
- elif [ $mode = 'verbose' ]; then
25
- if command_exists time ; then
26
- time "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
27
- return
28
- fi
14
+ if [ $mode = "quiet" ]; then
15
+ "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
16
+ elif command_exists /usr/bin/time ; then
17
+ /usr/bin/time "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
18
+ elif command_exists time ; then
19
+ time "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
20
+ else
21
+ "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
29
22
  fi
30
- "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
31
23
  }
32
24
 
33
25
  puts () {
34
- echo "$1" > $ostream
26
+ if [ $mode = "verbose" ]; then
27
+ echo "$1"
28
+ fi
35
29
  }
36
30
 
37
31
  write () {
38
- echo -n "$1" > $ostream
32
+ if [ $mode = "verbose" ]; then
33
+ echo -n "$1"
34
+ fi
39
35
  }
40
36
 
41
37
  view_file () {
42
38
  filename="$1"
43
- write '<'
44
- cat "$filename" > $ostream
45
- puts '>'
39
+ write "<"
40
+ cat "$filename"
41
+ puts ">"
46
42
  }
47
43
 
48
44
  report_case () {
49
- write ' Input: '
45
+ if [ $mode = "quiet" ]; then
46
+ return
47
+ fi
48
+ write " Input: "
50
49
  view_file "$data_d/$test_case.in"
51
- write ' Expected: '
50
+ write " Expected: "
52
51
  view_file "$data_d/$test_case.out"
53
- write ' Received: '
52
+ write " Received: "
54
53
  view_file "$output_d/$test_case.out"
55
54
  }
56
55
 
56
+ delegate () {
57
+ if command_exists ruby ; then
58
+ runner_rb="$(dirname $0)/runner.rb"
59
+ ruby "$runner_rb" "$mode" "$solver" "$data_d" "$output_d"
60
+ exit 0
61
+ fi
62
+ }
63
+
57
64
  init () {
58
65
  export TIME="Time: %es - Memory: %MK"
59
66
  export TIMEFORMAT=%3lR
@@ -62,13 +69,8 @@ init () {
62
69
  mkdir "$output_d"
63
70
  fi
64
71
 
65
- if [ "$mode" = 'verbose' ]; then
66
- ostream=/dev/stdout
67
- elif [ "$mode" = 'file' ]; then
68
- ostream=log
69
- fi
70
-
71
72
  dir=`dirname $0`
73
+ echo "[gettc] Compile checker"
72
74
  checker="$dir/../build/check"
73
75
  if [ ! -x "$checker" ]; then
74
76
  undo=`pwd`
@@ -79,14 +81,14 @@ init () {
79
81
  }
80
82
 
81
83
  main () {
82
- cases=0
84
+ echo "[gettc] Run test cases"
83
85
 
86
+ cases=0
84
87
  fails=0
85
-
86
88
  errors=0
87
- failstr=''
89
+ failstr=""
90
+ errorstr=""
88
91
 
89
- errorstr=''
90
92
  for input in "$data_d"/*.in; do
91
93
  if [ -f "$input" ]; then
92
94
  cases=$(( cases + 1 ))
@@ -94,37 +96,39 @@ main () {
94
96
  test_case=`basename "$input"`
95
97
  test_case=${test_case%.in}
96
98
 
97
- write "Check $test_case ... "
99
+ write "Case $test_case ... "
98
100
  timeit "$solver" "$data_d/$test_case.in" "$output_d/$test_case.out"
99
- "$checker" "$data_d/$test_case.out" "$output_d/$test_case.out" > $ostream
101
+ "$checker" "$data_d/$test_case.out" "$output_d/$test_case.out"
100
102
  retcode=$?
101
103
 
102
104
  if [ $retcode -eq 0 ]; then
103
- puts 'Passed'
105
+ puts "Passed"
104
106
 
105
107
  elif [ $retcode -eq 1 ]; then
106
108
  fails=$(( fails + 1 ))
107
109
  failstr="$failstr $test_case"
108
- puts 'Failed'
110
+ puts "Failed"
109
111
  report_case "$test_case"
110
112
 
111
113
  else
112
114
  errors=$(( errors + 1 ))
113
115
  errorstr="$errorstr $test_case"
114
- puts 'Error'
116
+ puts "Error"
115
117
  report_case "$test_case"
116
118
  fi
117
119
  fi
118
120
  done
119
- echo "$cases cases checked, $fails failed, $errors errored"
121
+
122
+ echo "[gettc] Summary"
123
+ echo "$cases cases checked, $fails failures, $errors errors"
120
124
  if [ $fails -gt 0 ]; then
121
- echo "Failed cases:${failstr}"
125
+ echo "Failures:${failstr}"
122
126
  fi
123
127
  if [ $errors -gt 0 ]; then
124
- echo "Errored cases:${errorstr}"
128
+ echo "Errors:${errorstr}"
125
129
  fi
126
-
127
130
  }
128
131
 
132
+ delegate
129
133
  init
130
134
  main
@@ -4,7 +4,7 @@ DATA_D = ../../data
4
4
  COMPILER = g++ -std=gnu++0x -I$(GETTC_HOME)/include/cpp
5
5
  RUNNER = sh ../../bin/runner.sh
6
6
 
7
- run = $(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
7
+ run = @$(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
8
8
 
9
9
  default : usage
10
10
 
@@ -12,11 +12,14 @@ usage :
12
12
  @cat $(GETTC_HOME)/usage
13
13
 
14
14
  setup :
15
- if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
15
+ @if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
16
+ @echo "[gettc] Compile solver"
16
17
 
17
- main : <%= prob.name %>Runner.cpp <%= prob.name %>.cpp setup
18
+ $(OUTPUT_D)/<%= prob.name %>Runner: <%= prob.name %>Runner.cpp <%= prob.name %>.cpp
18
19
  $(COMPILER) -o $(OUTPUT_D)/<%= prob.name %>Runner $<
19
20
 
21
+ main: setup $(OUTPUT_D)/<%= prob.name %>Runner
22
+
20
23
  demo : main
21
24
  $(call run,verbose,demo)
22
25
 
@@ -27,4 +30,4 @@ sysv : main
27
30
  $(call run,verbose,sys)
28
31
 
29
32
  clean :
30
- rm -rf $(OUTPUT_D)
33
+ @rm -rf $(OUTPUT_D)
@@ -3,7 +3,7 @@ OUTPUT_D =../../build/go
3
3
  DATA_D = ../../data
4
4
  RUNNER = sh ../../bin/runner.sh
5
5
 
6
- run = $(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
6
+ run = @$(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
7
7
 
8
8
  default : usage
9
9
 
@@ -11,11 +11,14 @@ usage :
11
11
  @cat $(GETTC_HOME)/usage
12
12
 
13
13
  setup :
14
- if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
14
+ @if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
15
+ @echo "[gettc] Compile solver"
15
16
 
16
- main : <%= prob.name %>Runner.go <%= prob.name %>/<%= prob.name %>.go setup
17
+ $(OUTPUT_D)/<%= prob.name %>Runner: <%= prob.name %>Runner.go <%= prob.name %>/<%= prob.name %>.go
17
18
  export GOPATH="$$GOPATH<%= File::PATH_SEPARATOR %>$(GETTC_HOME)/include/go" && go build -o $(OUTPUT_D)/<%= prob.name %>Runner <%= prob.name %>Runner.go
18
19
 
20
+ main: setup $(OUTPUT_D)/<%= prob.name %>Runner
21
+
19
22
  demo : main
20
23
  $(call run,verbose,demo)
21
24
 
@@ -26,4 +29,4 @@ sysv : main
26
29
  $(call run,verbose,sys)
27
30
 
28
31
  clean :
29
- rm -rf $(OUTPUT_D)
32
+ @rm -rf $(OUTPUT_D)
@@ -4,7 +4,7 @@ DATA_D = ../../data
4
4
  COMPILER = ghc -i$(GETTC_HOME)/include/haskell -outputdir $(OUTPUT_D)
5
5
  RUNNER = sh ../../bin/runner.sh
6
6
 
7
- run = $(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
7
+ run = @$(RUNNER) $1 $(OUTPUT_D)/<%= prob.name %>Runner $(DATA_D)/$2 $(OUTPUT_D)/$2
8
8
 
9
9
  default : usage
10
10
 
@@ -12,11 +12,14 @@ usage :
12
12
  @cat $(GETTC_HOME)/usage
13
13
 
14
14
  setup :
15
- if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
15
+ @if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
16
+ @echo "[gettc] Compile solver"
16
17
 
17
- main : <%= prob.name %>Runner.hs <%= prob.name %>.hs setup
18
+ $(OUTPUT_D)/<%= prob.name %>Runner: <%= prob.name %>Runner.hs <%= prob.name %>.hs
18
19
  $(COMPILER) -o $(OUTPUT_D)/<%= prob.name %>Runner $<
19
20
 
21
+ main: setup $(OUTPUT_D)/<%= prob.name %>Runner
22
+
20
23
  demo : main
21
24
  $(call run,verbose,demo)
22
25
 
@@ -27,4 +30,4 @@ sysv : main
27
30
  $(call run,verbose,sys)
28
31
 
29
32
  clean :
30
- rm -rf $(OUTPUT_D)
33
+ @rm -rf $(OUTPUT_D)
@@ -6,13 +6,13 @@ usage :
6
6
  @cat $(GETTC_HOME)/usage
7
7
 
8
8
  demo :
9
- ant demo
9
+ @ant demo
10
10
 
11
11
  sys :
12
- ant sys
12
+ @ant sys
13
13
 
14
14
  sysv :
15
- ant sysv
15
+ @ant sysv
16
16
 
17
17
  clean :
18
- ant clean
18
+ @ant clean
@@ -3,13 +3,13 @@ OUTPUT_D = ../../build/python
3
3
  DATA_D = ../../data
4
4
  RUNNER = sh ../../bin/runner.sh
5
5
 
6
- run = $(RUNNER) $1 ./<%= prob.name %>Runner.py $(DATA_D)/$2 $(OUTPUT_D)/$2
6
+ run = @$(RUNNER) $1 ./<%= prob.name %>Runner.py $(DATA_D)/$2 $(OUTPUT_D)/$2
7
7
 
8
8
  default : usage
9
9
 
10
10
  setup :
11
- if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
12
- chmod +x <%= prob.name %>Runner.py
11
+ @if [ ! -d $(OUTPUT_D) ]; then mkdir -p $(OUTPUT_D); fi
12
+ @chmod +x <%= prob.name %>Runner.py
13
13
 
14
14
  usage :
15
15
  @cat $(GETTC_HOME)/usage
@@ -24,4 +24,4 @@ sysv : setup
24
24
  $(call run,verbose,sys)
25
25
 
26
26
  clean :
27
- rm -rf $(OUTPUT_D)
27
+ @rm -rf $(OUTPUT_D)
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.7.5.2
4
+ version: '1.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot
@@ -78,9 +78,14 @@ 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
85
  - dist/include/python/topcoder/errors.py
82
86
  - dist/include/python/topcoder/reader.py
83
87
  - dist/include/python/topcoder/writer.py
88
+ - dist/template/bin/runner.rb
84
89
  - dist/template/bin/runner.sh
85
90
  - dist/template/data/demo/{examples_d}
86
91
  - dist/template/data/sys/{systests_d}