unitTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <math.h>
  2. //const float PI_F = 3.14f;
  3. float customRound(float number) {
  4. float factor = pow(10, 5);
  5. return round(number * factor) / factor;
  6. };
  7. Describe(circo_geometry)
  8. {
  9. It(test1) {
  10. Circle circo(2);
  11. Assert::That((int)(customRound(circo.getArea()) * 100), Equals((int)(12.56f * 100)));
  12. }
  13. It(test2) {
  14. Circle circo(2);
  15. Assert::That((int)(customRound(circo.getPerimeter()) * 100), Equals((int)(12.56f * 100)));
  16. }
  17. It(test3) {
  18. Circle circo(20);
  19. Assert::That((int)(customRound(circo.getArea()) * 10), Equals((int)(1256.0f * 10)));
  20. }
  21. It(test4) {
  22. Circle circo(20);
  23. Assert::That((int)(customRound(circo.getPerimeter()) * 10), Equals((int)(125.6f * 10)));
  24. }
  25. It(test5) {
  26. Circle circo(4.4);
  27. Assert::That((int)(customRound(circo.getArea()) * 10000), Equals((int)(60.7904f * 10000)));
  28. }
  29. It(test6) {
  30. Circle circo(4.4);
  31. Assert::That((int)(customRound(circo.getPerimeter()) * 1000), Equals((int)(27.632f * 1000)));
  32. }
  33. //scroll down for spoilers that are hard to use
  34. /*
  35. It(test7) {
  36. int randomInt = rand() % 100 + 1; // random number between 1 and 100
  37. Circle circo(randomInt);
  38. Assert::That((int)(customRound(circo.getArea()) * 1000000), Equals((int)(PI_F * pow(randomInt, 2) * 1000000)));
  39. }
  40. It(test8) {
  41. int randomInt = rand() % 100 + 1; // random number between 1 and 100
  42. Circle circo(randomInt);
  43. Assert::That((int)(customRound(circo.getPerimeter()) * 100000), Equals((int)(2 * PI_F * randomInt * 100000)));
  44. }
  45. */
  46. };