Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using NUnit.Framework;
  3.  
  4. namespace Manipulation
  5. {
  6. public class TriangleTask
  7. {
  8. public static double GetABAngle(double a, double b, double c)
  9. {
  10. if (a < 0 || b < 0 || c < 0)
  11. {
  12. return Double.NaN;
  13. }
  14. if (b + c < a || a + c < b || a + b < c)
  15. {
  16. return Double.NaN;
  17. }
  18. return Math.Acos((a * a + b * b - c * c) / 2 * a * b);
  19. }
  20. }
  21.  
  22. [TestFixture]
  23. public class TriangleTask_Tests
  24. {
  25. [TestCase(3, 4, 5, Math.PI / 2)]
  26. [TestCase(4, 5, 3, 0.6435)]
  27. [TestCase(3, 5, 4, 0.9273)]
  28. [TestCase(1, 1, 1, Math.PI / 3)]
  29. [TestCase(0, 0, 0, Double.NaN)]
  30. [TestCase(1, 3, 5, Double.NaN)]
  31. [TestCase(3, 5, 1, Double.NaN)]
  32. [TestCase(5, 1, 3, Double.NaN)]
  33. [TestCase(1, 2, 3, Math.PI)]
  34. [TestCase(2, 3, 1, 0)]
  35. [TestCase(3, 1, 2, 0)]
  36.  
  37. public void TestGetABAngle(double a, double b, double c, double expectedAngle)
  38. {
  39. var angle = TriangleTask.GetABAngle(a, b, c);
  40. if (Double.IsNaN(expectedAngle))
  41. Assert.IsNaN(angle);
  42. Assert.AreEqual(expectedAngle, angle, 1e-5);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement