/tutorial/triangle/version3/triangle.e

http://github.com/tybor/Liberty · Specman e · 63 lines · 45 code · 11 blank · 7 comment · 0 complexity · fcec626c8034ac7b06d0fb29cf641587 MD5 · raw file

  1. class TRIANGLE
  2. -- Description of TRIANGLEs objects.
  3. creation {ANY}
  4. make
  5. feature {ANY}
  6. p1: POINT
  7. -- First point.
  8. p2: POINT
  9. -- Second point.
  10. p3: POINT
  11. -- Third point.
  12. translate (dx, dy: REAL) is
  13. -- To translate `Current' using `dx' and `dy'.
  14. do
  15. p1.translate(dx, dy)
  16. p2.translate(dx, dy)
  17. p3.translate(dx, dy)
  18. end
  19. display_on (stream: OUTPUT_STREAM) is
  20. -- To display `Current' on the `stream'.
  21. require
  22. stream.is_connected
  23. do
  24. stream.put_string("TRIANGLE[%N%T")
  25. p1.display
  26. stream.put_string("%N%T")
  27. p2.display
  28. stream.put_string("%N%T")
  29. p3.display
  30. stream.put_string("%T]%N")
  31. end
  32. feature {}
  33. make (a, b, c: POINT) is
  34. -- To create a new TRIANGLE.
  35. require
  36. a /= Void
  37. b /= Void
  38. c /= Void
  39. do
  40. p1 := a
  41. p2 := b
  42. p3 := c
  43. ensure
  44. p1 = a
  45. p2 = b
  46. p3 = c
  47. end
  48. invariant
  49. p1 /= Void
  50. p2 /= Void
  51. p3 /= Void
  52. end -- class TRIANGLE