Class: Testrus::Runner::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/testrus/runner/run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, test) ⇒ Run

Responsible for extracting data from the run of the program. See the public methods for what information can be extracted. This class only reads output that is run with the command: ‘/usr/bin/time -l #program`.

TODO: Test if this runner works on all UNIX-based operating systems, or only OS X.

output - The String output from the command ‘/usr/bin/time -l program` test - The Test that the input origins from.



16
17
18
19
# File 'lib/testrus/runner/run.rb', line 16

def initialize(output, test)
  @output = output
  @test = test
end

Instance Attribute Details

#outputObject (readonly)

Public: Extracts the output against the input from the entire output which also inclues the time and memory information.



53
54
55
# File 'lib/testrus/runner/run.rb', line 53

def output
  @output
end

#testObject (readonly)

Returns the value of attribute test.



4
5
6
# File 'lib/testrus/runner/run.rb', line 4

def test
  @test
end

Instance Method Details

#memory_usageObject

Public: Extracts the memory usage from the output.



22
23
24
# File 'lib/testrus/runner/run.rb', line 22

def memory_usage
  bytes_to_mb(raw_memory_usage)
end

#passed?Boolean

Public: Boolean value of whether the test passed.

Returns:

  • (Boolean)


42
43
44
# File 'lib/testrus/runner/run.rb', line 42

def passed?
  output == @test.expected_output
end

#real_timeObject

Public: Extracts the real time from the output.



27
28
29
# File 'lib/testrus/runner/run.rb', line 27

def real_time
  time "real"
end

#sys_timeObject

Public: Extracts the sys time from the output.



37
38
39
# File 'lib/testrus/runner/run.rb', line 37

def sys_time
  time "sys"
end

#user_timeObject

Public: Extracts the user time from the output.



32
33
34
# File 'lib/testrus/runner/run.rb', line 32

def user_time
  time "user"
end

#within_constraints?Boolean

Public: Within usual constraints for time and memory

Returns:

  • (Boolean)


47
48
49
# File 'lib/testrus/runner/run.rb', line 47

def within_constraints?
  memory_usage <= 64.00 && real_time <= 1.00
end