/tutorial/time/example2.e

http://github.com/tybor/Liberty · Specman e · 42 lines · 34 code · 4 blank · 4 comment · 2 complexity · 61a467ac92c301fda4f93d40c9d0bdeb MD5 · raw file

  1. class EXAMPLE2
  2. --
  3. -- This example shows how to know about time variation using
  4. -- class TIME.
  5. --
  6. create {ANY}
  7. make
  8. feature {}
  9. make
  10. local
  11. time1, time2: TIME; clock: CLOCK; clock_value1, clock_value2, periods: INTEGER; seconds: REAL
  12. do
  13. if clock.value >= 0 then
  14. clock_value1 := clock.value
  15. end
  16. time1.update
  17. from
  18. time2.update
  19. until
  20. time2 > time1
  21. loop
  22. time2.update
  23. end
  24. clock_value2 := clock.value
  25. io.put_string("Elapsed time: ")
  26. io.put_real_format(time1.elapsed_seconds(time2).floor, 0)
  27. io.put_string(" seconds%N")
  28. if clock_value1 >= 0 then
  29. io.put_string("Elapsed time in number of clock periods: ")
  30. periods := clock_value2 - clock_value1
  31. io.put_integer(periods)
  32. io.put_string(" (sec: ")
  33. seconds := periods / clock.periods_per_second
  34. io.put_real(seconds)
  35. io.put_string(")%N")
  36. end
  37. end
  38. end -- class EXAMPLE2