most 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/Copying.txt +679 -0
  2. data/History.txt +15 -0
  3. data/Manifest.txt +95 -0
  4. data/PostInstall.txt +6 -0
  5. data/Rakefile +44 -0
  6. data/Readme.rdoc +146 -0
  7. data/bin/most +31 -0
  8. data/lib/most.rb +52 -0
  9. data/lib/most/context.rb +244 -0
  10. data/lib/most/core.rb +171 -0
  11. data/lib/most/di/container.rb +148 -0
  12. data/lib/most/di/proxy.rb +55 -0
  13. data/lib/most/di/service.rb +63 -0
  14. data/lib/most/di/service_factory.rb +40 -0
  15. data/lib/most/environment.rb +67 -0
  16. data/lib/most/executor.rb +80 -0
  17. data/lib/most/helpers/array.rb +31 -0
  18. data/lib/most/helpers/hash.rb +25 -0
  19. data/lib/most/helpers/kernel.rb +35 -0
  20. data/lib/most/helpers/memory_out.rb +93 -0
  21. data/lib/most/helpers/numeric.rb +59 -0
  22. data/lib/most/helpers/object.rb +65 -0
  23. data/lib/most/helpers/symbol.rb +31 -0
  24. data/lib/most/interfaces/meta_programmable.rb +59 -0
  25. data/lib/most/starter.rb +126 -0
  26. data/lib/most/structures/box.rb +199 -0
  27. data/lib/most/structures/submission.rb +117 -0
  28. data/lib/most/structures/test_case.rb +173 -0
  29. data/lib/most/structures/test_runner.rb +103 -0
  30. data/lib/most/structures/types/options.rb +67 -0
  31. data/lib/most/structures/types/path.rb +39 -0
  32. data/lib/most/structures/types/report.rb +84 -0
  33. data/lib/most/submissions/cpp_memory_out_sample.rb +34 -0
  34. data/lib/most/submissions/cpp_sample.rb +36 -0
  35. data/lib/most/submissions/cpp_timeout_sample.rb +34 -0
  36. data/lib/most/submissions/cs_sample.rb +36 -0
  37. data/lib/most/submissions/erlang_sample.rb +36 -0
  38. data/lib/most/submissions/haskell_sample.rb +36 -0
  39. data/lib/most/submissions/java_sample.rb +36 -0
  40. data/lib/most/submissions/lisp_sample.rb +32 -0
  41. data/lib/most/submissions/lua_sample.rb +36 -0
  42. data/lib/most/submissions/ocaml_sample.rb +36 -0
  43. data/lib/most/submissions/pascal_sample.rb +36 -0
  44. data/lib/most/submissions/perl_sample.rb +32 -0
  45. data/lib/most/submissions/php_sample.rb +32 -0
  46. data/lib/most/submissions/python_sample.rb +32 -0
  47. data/lib/most/submissions/ruby_sample.rb +32 -0
  48. data/lib/most/submissions/vb_sample.rb +36 -0
  49. data/lib/most/tasks/general/win/cs.rb +60 -0
  50. data/lib/most/tasks/general/win/erlang.rb +86 -0
  51. data/lib/most/tasks/general/win/gcc.rb +39 -0
  52. data/lib/most/tasks/general/win/haskell.rb +75 -0
  53. data/lib/most/tasks/general/win/java.rb +72 -0
  54. data/lib/most/tasks/general/win/lisp.rb +59 -0
  55. data/lib/most/tasks/general/win/lua.rb +75 -0
  56. data/lib/most/tasks/general/win/ocaml.rb +77 -0
  57. data/lib/most/tasks/general/win/pascal.rb +73 -0
  58. data/lib/most/tasks/general/win/perl.rb +61 -0
  59. data/lib/most/tasks/general/win/php.rb +59 -0
  60. data/lib/most/tasks/general/win/python.rb +59 -0
  61. data/lib/most/tasks/general/win/ruby.rb +61 -0
  62. data/lib/most/tasks/general/win/vb.rb +60 -0
  63. data/lib/most/tasks/general/win/vc.rb +79 -0
  64. data/lib/most/tasks/general/win/vs.rb +52 -0
  65. data/samples/problem/solutions/cpp/main.cpp +9 -0
  66. data/samples/problem/solutions/cpp/tests.yml +19 -0
  67. data/samples/problem/solutions/cs/main.cs +17 -0
  68. data/samples/problem/solutions/cs/tests.yml +19 -0
  69. data/samples/problem/solutions/erlang/main.erl +2 -0
  70. data/samples/problem/solutions/erlang/tests.yml +19 -0
  71. data/samples/problem/solutions/haskell/main.hs +5 -0
  72. data/samples/problem/solutions/haskell/tests.yml +19 -0
  73. data/samples/problem/solutions/java/Main.java +14 -0
  74. data/samples/problem/solutions/java/tests.yml +19 -0
  75. data/samples/problem/solutions/lisp/main.lisp +1 -0
  76. data/samples/problem/solutions/lisp/tests.yml +19 -0
  77. data/samples/problem/solutions/lua/main.lua +4 -0
  78. data/samples/problem/solutions/lua/tests.yml +19 -0
  79. data/samples/problem/solutions/ocaml/main.ml +3 -0
  80. data/samples/problem/solutions/ocaml/tests.yml +19 -0
  81. data/samples/problem/solutions/pascal/main.pas +5 -0
  82. data/samples/problem/solutions/pascal/tests.yml +19 -0
  83. data/samples/problem/solutions/perl/main.pl +2 -0
  84. data/samples/problem/solutions/perl/tests.yml +19 -0
  85. data/samples/problem/solutions/php/main.php +1 -0
  86. data/samples/problem/solutions/php/tests.yml +19 -0
  87. data/samples/problem/solutions/python/main.py +1 -0
  88. data/samples/problem/solutions/python/tests.yml +19 -0
  89. data/samples/problem/solutions/ruby/main.rb +1 -0
  90. data/samples/problem/solutions/ruby/tests.yml +19 -0
  91. data/samples/problem/solutions/vb/main.vb +14 -0
  92. data/samples/problem/solutions/vb/tests.yml +19 -0
  93. data/samples/time_memory/solutions/cpp/main.cpp +21 -0
  94. data/samples/time_memory/solutions/cpp/tests.yml +19 -0
  95. data/tasks/samples.rb +31 -0
  96. metadata +242 -0
@@ -0,0 +1,67 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'singleton'
20
+
21
+ module Most
22
+
23
+ class Environment
24
+ include Singleton
25
+
26
+ attr_reader :arguments
27
+
28
+ attr_reader :logger
29
+ attr_reader :options, :modes, :tasks
30
+
31
+ def initialize()
32
+ @arguments = ARGV
33
+
34
+ @logger = SERVICES[:logger]
35
+
36
+ @options = PARAMETERS[:options]
37
+ @modes = PARAMETERS[:modes]
38
+ @tasks = PARAMETERS[:tasks]
39
+ end
40
+
41
+ def log_error(exception, message)
42
+ @logger.error(message)
43
+ @logger.error(exception.message)
44
+
45
+ unless @modes.nil?
46
+ @logger.error(exception.backtrace) if @modes[:verbose] or
47
+ @modes[:debug]
48
+ end
49
+
50
+ GLOBALS[:exit_code] = 1
51
+ end
52
+
53
+ def log_warning(text)
54
+ @logger.warn(text)
55
+ end
56
+
57
+ def log_message(text)
58
+ @logger.info(text)
59
+ end
60
+
61
+ def show_message(message, is_log_data = false)
62
+ puts "#{message}"
63
+ log_message(message) if is_log_data
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,80 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Most
20
+
21
+ class Executor
22
+ def initialize()
23
+ @environment = SERVICES[:environment]
24
+ @options = @environment.options
25
+ @tasks = @environment.tasks
26
+ end
27
+
28
+ def run()
29
+ if @tasks[:show_version]
30
+ output_version()
31
+ elsif @tasks[:show_help]
32
+ output_help()
33
+ else
34
+ begin
35
+ output_result(SERVICES[:core].run())
36
+ rescue Exception => e
37
+ @environment.log_error(e, 'Core failure')
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+ def output_result(result)
44
+ file = @options[:output_file]
45
+
46
+ unless file.nil?
47
+ begin
48
+ File.open(File.expand_path(file), 'w+') do |io|
49
+ io.write(result)
50
+ end
51
+ rescue Exception => e
52
+ @environment.log_error(e, 'Failed to output the report')
53
+ puts(result)
54
+ end
55
+ else
56
+ puts(result)
57
+ end
58
+ end
59
+
60
+ def output_help()
61
+ output_version()
62
+ output_options()
63
+ end
64
+
65
+ def output_version()
66
+ @environment.show_message("#{FULL_NAME} version #{VERSION}")
67
+ @environment.show_message("#{COPYRIGHT}")
68
+ end
69
+
70
+ def output_options()
71
+ @environment.show_message("Available options: \n\n")
72
+ @environment.show_message("Usage: #{UNIX_NAME} {[option] [parameter]}")
73
+
74
+ SERVICES[:starter].usage.each do |name, options|
75
+ @environment.show_message("\n\t#{options[2]}\n\t\t#{options[0]}, #{options[1]}")
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,31 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ class Array
20
+ def /(value)
21
+ result = nil
22
+
23
+ if value.is_a?(Symbol)
24
+ result = self + [value]
25
+ elsif value.is_a?(Array)
26
+ result = self + value
27
+ end
28
+
29
+ result
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'most/structures/types/options'
20
+
21
+ class Hash
22
+ def to_options()
23
+ Most::Options.new(self)
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'stringio'
20
+
21
+ module Kernel
22
+ def fake_std()
23
+ result = [StringIO.new(), StringIO.new()]
24
+
25
+ $stdout = result.first()
26
+ $stderr = result.last()
27
+
28
+ yield if block_given?
29
+
30
+ return result
31
+ ensure
32
+ $stdout = STDOUT
33
+ $stderr = STDERR
34
+ end
35
+ end
@@ -0,0 +1,93 @@
1
+ module Most
2
+ module MemoryOut
3
+ class Error < Interrupt; end
4
+ class ExitException < Exception; end
5
+
6
+ THIS_FILE = /\A#{Regexp.quote(__FILE__)}:/o
7
+ CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0
8
+
9
+ def generic_memory_out(bytes, pid = nil, precision = 0.1, klass = nil, checking_proc = method(:memory), &block)
10
+ return yield if bytes.nil? and block_given?
11
+
12
+ current_thread = nil
13
+ checker_thread = nil
14
+
15
+ exception = klass || Class.new(ExitException)
16
+
17
+ begin
18
+ current_thread = Thread.current
19
+ checker_thread = Thread.start do
20
+ loop do
21
+ memory_report = checking_proc.call(pid)
22
+
23
+ GLOBALS[:memory] ||= []
24
+ GLOBALS[:memory] << memory_report
25
+
26
+ if memory_report > bytes
27
+ current_thread.raise(exception)
28
+ end
29
+
30
+ sleep(precision)
31
+ end
32
+ end
33
+
34
+ yield bytes if block_given?
35
+
36
+ rescue exception => e
37
+ rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
38
+ (bt = e.backtrace).reject! {|m| rej =~ m}
39
+ level = -caller(CALLER_OFFSET).size
40
+
41
+ while THIS_FILE =~ bt[level]
42
+ bt.delete_at(level)
43
+ level += 1
44
+ end
45
+
46
+ raise unless klass.nil?
47
+
48
+ raise(Error, e.message, e.backtrace)
49
+ ensure
50
+ checker_thread.kill() if not checker_thread.nil? and checker_thread.alive?
51
+ end
52
+ end
53
+
54
+ def memory_out(bytes, pid = nil, precision = 0.1, klass = nil, &block)
55
+ generic_memory_out(bytes, pid, precision, klass, method(:memory), &block)
56
+ end
57
+
58
+ def virtual_memory_out(bytes, pid = nil, precision = 0.1, klass = nil, &block)
59
+ generic_memory_out(bytes, pid, precision, klass, method(:virtual_memory), &block)
60
+ end
61
+
62
+ def total_memory_out(bytes, pid = nil, precision = 0.1, klass = nil, &block)
63
+ generic_memory_out(bytes, pid, precision, klass, method(:total_memory), &block)
64
+ end
65
+
66
+ def memory(pid = Process.pid)
67
+ result = 0
68
+
69
+ pid ||= GLOBALS[:pid]
70
+ result = SERVICES[:process_table].memory(pid) unless pid.nil?
71
+
72
+ result
73
+ end
74
+
75
+ def virtual_memory(pid = Process.pid)
76
+ result = 0
77
+
78
+ pid ||= GLOBALS[:pid]
79
+ result = SERVICES[:process_table].virtual_memory(pid) unless pid.nil?
80
+
81
+ result
82
+ end
83
+
84
+ def total_memory(pid = Process.pid)
85
+ memory(pid) + virtual_memory(pid)
86
+ end
87
+
88
+ module_function :generic_memory_out
89
+
90
+ module_function :memory_out, :virtual_memory_out, :total_memory_out
91
+ module_function :memory, :virtual_memory, :total_memory
92
+ end
93
+ end
@@ -0,0 +1,59 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ class Numeric
20
+ def milliseconds()
21
+ self / 100.0
22
+ end
23
+
24
+ def seconds()
25
+ self
26
+ end
27
+
28
+ def minutes()
29
+ self * 60
30
+ end
31
+
32
+ def hours()
33
+ self * 3600
34
+ end
35
+
36
+ def bits()
37
+ self * 8
38
+ end
39
+
40
+ def bytes()
41
+ self
42
+ end
43
+
44
+ def kilobytes()
45
+ self * 1024
46
+ end
47
+
48
+ def megabytes()
49
+ self * 1048576
50
+ end
51
+
52
+ def gigabytes()
53
+ self * 1073741824
54
+ end
55
+
56
+ def petabytes()
57
+ self * 1099511627776
58
+ end
59
+ end
@@ -0,0 +1,65 @@
1
+ # Most - Modular Open Software Tester.
2
+ # Copyright (C) 2009 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of Most.
5
+ #
6
+ # Most is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Most is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Most. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ class Object
20
+ def valid?(item, *args, &block)
21
+ result = item.nil? ? false : true
22
+
23
+ if result
24
+ args.each do |objects|
25
+ unless objects
26
+ result = false; break;
27
+ end
28
+ end
29
+
30
+ yield block if block_given?
31
+ end
32
+
33
+ result
34
+ end
35
+
36
+ def first_valid(item, *items)
37
+ result = item
38
+
39
+ if result.nil?
40
+ items.each do |object|
41
+ unless object.nil?
42
+ result = object; break
43
+ end
44
+ end
45
+ end
46
+
47
+ result
48
+ end
49
+
50
+ def try(method_name, *args, &block)
51
+ send(method_name, *args, &block) if respond_to?(method_name, true)
52
+ end
53
+
54
+ unless method_defined? :intern
55
+ define_method(:intern) do
56
+ result = self
57
+
58
+ unless is_a?(Symbol)
59
+ result.to_s().intern()
60
+ end
61
+
62
+ result
63
+ end
64
+ end
65
+ end