fork download
  1. def expectedPremiums = [6.19, 6.47, 6.90]
  2. def xmlString = """<root xmlns:b="test">
  3. <b:quote-data>
  4. <b:premium>6.13</b:premium>
  5. </b:quote-data>
  6. <b:quote-data>
  7. <b:premium>6.45</b:premium>
  8. </b:quote-data>
  9. <b:quote-data>
  10. <b:premium>6.91</b:premium>
  11. </b:quote-data>
  12. </root>"""
  13. def xml = new XmlSlurper().parseText(xmlString)
  14. def premiums = xml.'**'.findAll {it.name() == 'premium'}*.toBigDecimal()
  15. println premiums
  16. def tolerance = 0.05
  17. def failurePremiums = [:]
  18. expectedPremiums.eachWithIndex { expected, index ->
  19. if ((expected-tolerance) <= premiums[index] && premiums[index] <= (expected+tolerance)) {
  20. println "${premiums[index]} is in range"
  21. } else {
  22. println "${premiums[index]} is not falling in range, failed"
  23. failurePremiums[expected] = premiums[index]
  24. }
  25. }
  26. assert !failurePremiums, "Not matched data(expected vs actual) : ${failurePremiums}"
  27.  
Runtime error #stdin #stdout #stderr 1.11s 4456448KB
stdin
Standard input is empty
stdout
[6.13, 6.45, 6.91]
6.13 is not falling in range, failed
6.45 is in range
6.91 is in range
stderr
Caught: java.lang.AssertionError: Not matched data(expected vs actual) : [6.19:6.13]. Expression: failurePremiums. Values: failurePremiums = [6.19:6.13]
java.lang.AssertionError: Not matched data(expected vs actual) : [6.19:6.13]. Expression: failurePremiums. Values: failurePremiums = [6.19:6.13]
	at prog.run(prog.groovy:26)