Advertisement
Guest User

Nunit

a guest
Feb 14th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using NUnit.Framework;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10. class Point
  11. {
  12. private double x;
  13. private double y;
  14.  
  15. public static void Main(String[] args)
  16. {
  17.  
  18. }
  19.  
  20.  
  21. public Point()
  22. {
  23. x = y = 0;
  24. }
  25.  
  26. public Point(double newX, double newY)
  27. {
  28. x = newX;
  29. y = newY;
  30. }
  31.  
  32. // returns x and y values of the point, respectively
  33. public double getX() { return x; }
  34. public double getY() { return y; }
  35.  
  36. // Stretches the point by increasing the distance between the point and zero
  37. // by the factor scale. For example, applying stretch(3) to the point (2,3)
  38. // should yield (6,9). Only non-negative scale values should be allowed.
  39. public void stretch(double scale)
  40. {
  41. x *= scale;
  42. y *= scale;
  43. }
  44.  
  45. // calculates the stright-line distance between two points. The value should
  46. // always be non-negative.
  47. public double distance(Point other)
  48. {
  49. double ans = (x - other.getX()) * (x - other.getX()) + (y - other.getY()) * (y - other.getY());
  50. ans = Math.Sqrt(ans);
  51. return ans;
  52. }
  53.  
  54. // Rotates the point counter-clockwise by deg degrees. For example, applying
  55. // a 90 degree rotation to (1, 0) should give (0, 1).
  56. public void rotate(double deg)
  57. {
  58. double rotCos = Math.Cos(deg * Math.PI / 180);
  59. double rotSin = Math.Sin(deg * Math.PI / 180);
  60. double oldX = x;
  61. double oldY = y;
  62. x = oldX * rotCos - oldY * rotSin;
  63. y = oldX * rotSin + oldY * rotCos;
  64. }
  65.  
  66. // returns a string of the form "(x, y)" to display the point, x and y are
  67. // given to one decimal place
  68. public String toString()
  69. {
  70. return "(" + x + ", " + y + ")";
  71. }
  72.  
  73. // returns true if the distance of the point to (0,0) is closer than from
  74. // other to (0,0), false otherwise.
  75. public static bool operator <(Point p1, Point p2)
  76. {
  77. Point origin = new Point(); ;
  78. return p1.distance(origin) < p2.distance(origin);
  79. }
  80.  
  81. // returns true if the distance of the point to (0,0) is further than from
  82. // other to (0,0), false otherwise.
  83. public static bool operator >(Point p1, Point p2)
  84. {
  85. Point origin = new Point();
  86. return p1.distance(origin) > p2.distance(origin);
  87. }
  88. }
  89. [TestFixture]
  90. public class PointTest
  91. {
  92. [SetUp]
  93. double x = 2;
  94. double y = 6;
  95.  
  96. [Test]
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement