Module: Funit::Assertions

Included in:
Funit
Defined in:
lib/funit/assertions.rb

Instance Method Summary collapse

Instance Method Details

#isequal(line) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/funit/assertions.rb', line 82

def isequal(line)
  line.match(/\((\w+\(.*\)|[^,]+),(.+)\)/)
  @type = 'IsEqual'
  @condition = ".not.(#$1==#$2)"
  @message = "\"#$1 (\",#$1,\") is not\", #$2"
  syntaxError("invalid body for #@type",@suiteName) unless $&
  writeAssert
end

#isequalwithin(line) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/funit/assertions.rb', line 72

def isequalwithin(line)
  line.match(/\((.*)\)/)
  expected, actual, tolerance = *($1.get_args)
  @type = 'IsEqualWithin'
  @condition = ".not.(#{actual}+#{tolerance}.ge.#{expected} &\n             .and.#{actual}-#{tolerance}.le.#{expected})"
  @message = "\"#{expected} (\",#{expected},\") is not\",#{actual},\"within\",#{tolerance}"
  syntaxError("invalid body for #@type",@suiteName) unless $&
  writeAssert
end

#isfalse(line) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/funit/assertions.rb', line 53

def isfalse(line)
  line.match(/\((.+)\)/)
  @type = 'IsFalse'
  @condition = "#$1"
  @message = "\"#$1 is not false\""
  syntaxError("invalid body for #@type",@suiteName) unless $1=~/\S+/
  writeAssert
end

#isrealequal(line) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/funit/assertions.rb', line 62

def isrealequal(line)
  line.match(/\((.*)\)/)
  expected, actual = *($1.get_args)
  @type = 'IsRealEqual'
  @condition = ".not.(#{expected}+2*spacing(real(#{expected})).ge.#{actual} &\n             .and.#{expected}-2*spacing(real(#{expected})).le.#{actual})"
  @message = "\"#{actual} (\",#{actual},\") is not\",#{expected},\"within\",2*spacing(real(#{expected}))"
  syntaxError("invalid body for #@type",@suiteName) unless $&
  writeAssert
end

#istrue(line) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/funit/assertions.rb', line 44

def istrue(line)
  line.match(/\((.+)\)/)
  @type = 'IsTrue'
  @condition = ".not.(#$1)"
  @message = "\"#$1 is not true\""
  syntaxError("invalid body for #@type",@suiteName) unless $1=~/\S+/
  writeAssert
end

#writeAssertObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/funit/assertions.rb', line 91

def writeAssert
  <<-OUTPUT
  ! #@type assertion
  numAsserts = numAsserts + 1
  if (noAssertFailed) then
if (#@condition) then
  print *, " *#@type failed* in test #@testName &
          &[#{@suiteName}.fun:#{@lineNumber.to_s}]"
  print *, "  ", #@message
  print *, ""
  noAssertFailed = .false.
  numFailures    = numFailures + 1
else
  numAssertsTested = numAssertsTested + 1
endif
  endif
  OUTPUT
end