Aaaaa988

Untitled

Sep 27th, 2020
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "CppUnitTest.h"
  3. #include "../Lab1_Fraction/pch.h"
  4.  
  5. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  6. using namespace std;
  7. namespace FracClassTest {
  8.     TEST_CLASS(UnitTest1) {
  9. public:
  10.  
  11.     TEST_METHOD(Init_String_1) {
  12.         string fracString = "1/2";
  13.         TFrac fracClass(fracString);
  14.         Assert::AreEqual(fracString, fracClass.getFractionString());
  15.     }
  16.     TEST_METHOD(Init_String_2) {
  17.         string fracString = "111/2";
  18.         TFrac fracClass(fracString);
  19.         Assert::AreEqual(fracString, fracClass.getFractionString());
  20.     }
  21.     TEST_METHOD(Init_String_3) {
  22.         string fracString = "1/999";
  23.         TFrac fracClass(fracString);
  24.         Assert::AreEqual(fracString, fracClass.getFractionString());
  25.     }
  26.     TEST_METHOD(Init_String_4) {
  27.         string fracString = "100/10";
  28.         TFrac fracClass(fracString);
  29.         string fracCompar = "10/1";
  30.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  31.     }
  32.     TEST_METHOD(Init_String_5) {
  33.         string fracString = "-100/60";
  34.         TFrac fracClass(fracString);
  35.         string fracCompar = "-5/3";
  36.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  37.     }
  38.     TEST_METHOD(Init_String_6) {
  39.         string fracString = "0000003/0004";
  40.         TFrac fracClass(fracString);
  41.         string fracCompar = "3/4";
  42.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  43.     }
  44.     TEST_METHOD(Init_Number_1) {
  45.         TFrac fracClass(2, 4);
  46.         string fracCompar = "1/2";
  47.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  48.     }
  49.     TEST_METHOD(Init_Number_2) {
  50.         TFrac fracClass(17, 9);
  51.         string fracCompar = "17/9";
  52.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  53.     }
  54.     TEST_METHOD(Init_Number_3) {
  55.         TFrac fracClass(100, 100);
  56.         string fracCompar = "1/1";
  57.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  58.     }
  59.     TEST_METHOD(Init_Number_4) {
  60.         TFrac fracClass(-100, -99);
  61.         string fracCompar = "100/99";
  62.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  63.     }
  64.     TEST_METHOD(Init_Number_5) {
  65.         TFrac fracClass(0, 0);
  66.         string fracCompar = "0/1";
  67.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  68.     }
  69.     TEST_METHOD(Init_Number_6) {
  70.         TFrac fracClass(100, -5);
  71.         string fracCompar = "-20/1";
  72.         Assert::AreEqual(fracCompar, fracClass.getFractionString());
  73.     }
  74.     TEST_METHOD(Init_Copy_1) {
  75.         TFrac fracClass1(1, 4);
  76.         TFrac fracClass2(fracClass1);
  77.         Assert::AreEqual(fracClass1.getFractionString(), fracClass2.getFractionString());
  78.     }
  79.     TEST_METHOD(Init_Copy_2) {
  80.         TFrac fracClass1(-10, 1);
  81.         TFrac fracClass2(fracClass1);
  82.         Assert::AreEqual(fracClass1.getFractionString(), fracClass2.getFractionString());
  83.     }
  84.     TEST_METHOD(Add_1) {
  85.         TFrac fracClass1(1, 2);
  86.         TFrac fracClass2(-3, 4);
  87.         fracClass1 = fracClass1.add(fracClass2);
  88.         string answer = "-1/4";
  89.         Assert::AreEqual(answer, fracClass1.getFractionString());
  90.     }
  91.     TEST_METHOD(Add_2) {
  92.         TFrac fracClass1(-1, 2);
  93.         TFrac fracClass2(-1, 2);
  94.         fracClass1 = fracClass1.add(fracClass2);
  95.         string answer = "-1/1";
  96.         Assert::AreEqual(answer, fracClass1.getFractionString());
  97.     }
  98.     TEST_METHOD(Add_3) {
  99.         TFrac fracClass1(-6, 2);
  100.         TFrac fracClass2(6, 2);
  101.         fracClass1 = fracClass1.add(fracClass2);
  102.         string answer = "0/1";
  103.         Assert::AreEqual(answer, fracClass1.getFractionString());
  104.     }
  105.     TEST_METHOD(Add_4) {
  106.         TFrac fracClass1(50, 3);
  107.         TFrac fracClass2(0, 1);
  108.         fracClass1 = fracClass1.add(fracClass2);
  109.         string answer = "50/3";
  110.         Assert::AreEqual(answer, fracClass1.getFractionString());
  111.     }
  112.     TEST_METHOD(Multiply_1) {
  113.         TFrac fracClass1(-1, 2);
  114.         TFrac fracClass2(-1, 2);
  115.         fracClass1 = fracClass1.multiply(fracClass2);
  116.         string answer = "1/4";
  117.         Assert::AreEqual(answer, fracClass1.getFractionString());
  118.     }
  119.     TEST_METHOD(Multiply_2) {
  120.         TFrac fracClass1(1, 6);
  121.         TFrac fracClass2(0, 1);
  122.         fracClass1 = fracClass1.multiply(fracClass2);
  123.         string answer = "0/1";
  124.         Assert::AreEqual(answer, fracClass1.getFractionString());
  125.     }
  126.     TEST_METHOD(Multiply_3) {
  127.         TFrac fracClass1(1, 6);
  128.         TFrac fracClass2(1, 6);
  129.         fracClass1 = fracClass1.multiply(fracClass2);
  130.         string answer = "1/36";
  131.         Assert::AreEqual(answer, fracClass1.getFractionString());
  132.     }
  133.     TEST_METHOD(Multiply_4) {
  134.         TFrac fracClass1(-1, 6);
  135.         TFrac fracClass2(12, 1);
  136.         fracClass1 = fracClass1.multiply(fracClass2);
  137.         string answer = "-2/1";
  138.         Assert::AreEqual(answer, fracClass1.getFractionString());
  139.     }
  140.     TEST_METHOD(Substract_1) {
  141.         TFrac fracClass1(0, 1);
  142.         TFrac fracClass2(1, 1);
  143.         fracClass1 = fracClass1.substract(fracClass2);
  144.         string answer = "-1/1";
  145.         Assert::AreEqual(answer, fracClass1.getFractionString());
  146.     }
  147.     TEST_METHOD(Substract_2) {
  148.         TFrac fracClass1(5, 1);
  149.         TFrac fracClass2(1, 1);
  150.         fracClass1 = fracClass1.substract(fracClass2);
  151.         string answer = "4/1";
  152.         Assert::AreEqual(answer, fracClass1.getFractionString());
  153.     }
  154.     TEST_METHOD(Substract_3) {
  155.         TFrac fracClass1(1, 2);
  156.         TFrac fracClass2(1, 2);
  157.         fracClass1 = fracClass1.substract(fracClass2);
  158.         string answer = "0/1";
  159.         Assert::AreEqual(answer, fracClass1.getFractionString());
  160.     }
  161.     TEST_METHOD(Substract_4) {
  162.         TFrac fracClass1(-1, 6);
  163.         TFrac fracClass2(-1, 6);
  164.         fracClass1 = fracClass1.substract(fracClass2);
  165.         string answer = "0/1";
  166.         Assert::AreEqual(answer, fracClass1.getFractionString());
  167.     }
  168.     TEST_METHOD(Divide_1) {
  169.         TFrac fracClass1(5, 6);
  170.         TFrac fracClass2(1, 1);
  171.         fracClass1 = fracClass1.divide(fracClass2);
  172.         string answer = "5/6";
  173.         Assert::AreEqual(answer, fracClass1.getFractionString());
  174.     }
  175.     TEST_METHOD(Divide_2) {
  176.         TFrac fracClass1(1, 1);
  177.         TFrac fracClass2(5, 6);
  178.         fracClass1 = fracClass1.divide(fracClass2);
  179.         string answer = "6/5";
  180.         Assert::AreEqual(answer, fracClass1.getFractionString());
  181.     }
  182.     TEST_METHOD(Divide_3) {
  183.         TFrac fracClass1(0, 1);
  184.         TFrac fracClass2(5, 6);
  185.         fracClass1 = fracClass1.divide(fracClass2);
  186.         string answer = "0/1";
  187.         Assert::AreEqual(answer, fracClass1.getFractionString());
  188.     }
  189.     TEST_METHOD(Divide_4) {
  190.         TFrac fracClass1(2, 3);
  191.         TFrac fracClass2(7, 4);
  192.         fracClass1 = fracClass1.divide(fracClass2);
  193.         string answer = "8/21";
  194.         Assert::AreEqual(answer, fracClass1.getFractionString());
  195.     }
  196.     TEST_METHOD(Divide_5) {
  197.         TFrac fracClass1(2, 3);
  198.         TFrac fracClass2(2, 3);
  199.         fracClass1 = fracClass1.divide(fracClass2);
  200.         string answer = "1/1";
  201.         Assert::AreEqual(answer, fracClass1.getFractionString());
  202.     }
  203.     TEST_METHOD(Divide_6) {
  204.         TFrac fracClass1(-1, 3);
  205.         TFrac fracClass2(-9, 5);
  206.         fracClass1 = fracClass1.divide(fracClass2);
  207.         string answer = "5/27";
  208.         Assert::AreEqual(answer, fracClass1.getFractionString());
  209.     }
  210.     TEST_METHOD(Square_1) {
  211.         TFrac fracClass1(1, 3);
  212.         fracClass1 = fracClass1.square();
  213.         string answer = "1/9";
  214.         Assert::AreEqual(answer, fracClass1.getFractionString());
  215.     }
  216.     TEST_METHOD(Square_2) {
  217.         TFrac fracClass1(0, 1);
  218.         fracClass1 = fracClass1.square();
  219.         string answer = "0/1";
  220.         Assert::AreEqual(answer, fracClass1.getFractionString());
  221.     }
  222.     TEST_METHOD(Square_3) {
  223.         TFrac fracClass1(-2, 3);
  224.         fracClass1 = fracClass1.square();
  225.         string answer = "4/9";
  226.         Assert::AreEqual(answer, fracClass1.getFractionString());
  227.     }
  228.     TEST_METHOD(Reverse_1) {
  229.         TFrac fracClass1(-2, 3);
  230.         fracClass1 = fracClass1.reverse();
  231.         string answer = "-3/2";
  232.         Assert::AreEqual(answer, fracClass1.getFractionString());
  233.     }
  234.     TEST_METHOD(Reverse_2) {
  235.         TFrac fracClass1(0, 1);
  236.         fracClass1 = fracClass1.reverse();
  237.         string answer = "0/1";
  238.         Assert::AreEqual(answer, fracClass1.getFractionString());
  239.     }
  240.     TEST_METHOD(Reverse_3) {
  241.         TFrac fracClass1(5, 6);
  242.         fracClass1 = fracClass1.reverse();
  243.         string answer = "6/5";
  244.         Assert::AreEqual(answer, fracClass1.getFractionString());
  245.     }
  246.     TEST_METHOD(Minus_1) {
  247.         TFrac fracClass(0, 1);
  248.         string answer = "0/1";
  249.         fracClass = -fracClass;
  250.         Assert::AreEqual(answer, fracClass.getFractionString());
  251.     }
  252.     TEST_METHOD(Minus_2) {
  253.         TFrac fracClass(7, 4);
  254.         string answer = "-7/4";
  255.         fracClass = -fracClass;
  256.         Assert::AreEqual(answer, fracClass.getFractionString());
  257.     }
  258.     TEST_METHOD(Minus_3) {
  259.         TFrac fracClass(-5, 3);
  260.         string answer = "5/3";
  261.         fracClass = -fracClass;
  262.         Assert::AreEqual(answer, fracClass.getFractionString());
  263.     }
  264.     TEST_METHOD(Equal_1) {
  265.         TFrac fracClass1(1, 6);
  266.         TFrac fracClass2(1, 6);
  267.         Assert::IsTrue(fracClass1 == fracClass2);
  268.     }
  269.     TEST_METHOD(Equal_2) {
  270.         TFrac fracClass1(0, 6);
  271.         TFrac fracClass2(1, 6);
  272.         Assert::IsFalse(fracClass1 == fracClass2);
  273.     }
  274.     TEST_METHOD(Equal_3) {
  275.         TFrac fracClass1(-1, 6);
  276.         TFrac fracClass2(-1, 6);
  277.         Assert::IsTrue(fracClass1 == fracClass2);
  278.     }
  279.     TEST_METHOD(Equal_4) {
  280.         TFrac fracClass1(-1, 7);
  281.         TFrac fracClass2(1, 7);
  282.         Assert::IsFalse(fracClass1 == fracClass2);
  283.     }
  284.     TEST_METHOD(Equal_5) {
  285.         TFrac fracClass1(1, 6);
  286.         TFrac fracClass2(0, 1);
  287.         Assert::IsFalse(fracClass1 == fracClass2);
  288.     }
  289.     TEST_METHOD(Greater_1) {
  290.         TFrac fracClass1(1, 6);
  291.         TFrac fracClass2(0, 1);
  292.         Assert::IsTrue(fracClass1 > fracClass2);
  293.     }
  294.     TEST_METHOD(Greater_2) {
  295.         TFrac fracClass1(0, 1);
  296.         TFrac fracClass2(0, 1);
  297.         Assert::IsFalse(fracClass1 > fracClass2);
  298.     }
  299.     TEST_METHOD(Greater_3) {
  300.         TFrac fracClass1(-1, 6);
  301.         TFrac fracClass2(0, 1);
  302.         Assert::IsFalse(fracClass1 > fracClass2);
  303.     }
  304.     TEST_METHOD(Greater_4) {
  305.         TFrac fracClass1(17, 3);
  306.         TFrac fracClass2(16, 3);
  307.         Assert::IsTrue(fracClass1 > fracClass2);
  308.     }
  309.     TEST_METHOD(Greater_5) {
  310.         TFrac fracClass1(-2, 3);
  311.         TFrac fracClass2(-1, 3);
  312.         Assert::IsFalse(fracClass1 > fracClass2);
  313.     }
  314.     TEST_METHOD(GetNumeratorNum_1) {
  315.         TFrac fracClass(1, 23);
  316.         int expectedNum = 1;
  317.         Assert::AreEqual(expectedNum, fracClass.getNumeratorNumber());
  318.     }
  319.     TEST_METHOD(GetNumeratorNum_2) {
  320.         TFrac fracClass(-11, 2);
  321.         int expectedNum = -11;
  322.         Assert::AreEqual(expectedNum, fracClass.getNumeratorNumber());
  323.     }
  324.     TEST_METHOD(GetNumeratorNum_3) {
  325.         TFrac fracClass(0, 1);
  326.         int expectedNum = 0;
  327.         Assert::AreEqual(expectedNum, fracClass.getNumeratorNumber());
  328.     }
  329.     TEST_METHOD(GetDenominatorNum_1) {
  330.         TFrac fracClass(1, 222);
  331.         int expectedNum = 222;
  332.         Assert::AreEqual(expectedNum, fracClass.getDenominatorNumber());
  333.     }
  334.     TEST_METHOD(GetDenominatorNum_2) {
  335.         TFrac fracClass(-1, 222);
  336.         int expectedNum = 222;
  337.         Assert::AreEqual(expectedNum, fracClass.getDenominatorNumber());
  338.     }
  339.     TEST_METHOD(GetDenominatorNum_3) {
  340.         TFrac fracClass(0, 1);
  341.         int expectedNum = 1;
  342.         Assert::AreEqual(expectedNum, fracClass.getDenominatorNumber());
  343.     }
  344.     TEST_METHOD(GetNumeratorString_1) {
  345.         TFrac fracClass(1, 23);
  346.         string expectedNum = "1";
  347.         Assert::AreEqual(expectedNum, fracClass.getNumeratorString());
  348.     }
  349.     TEST_METHOD(GetNumeratorString_2) {
  350.         TFrac fracClass(-11, 2);
  351.         string expectedNum = "-11";
  352.         Assert::AreEqual(expectedNum, fracClass.getNumeratorString());
  353.     }
  354.     TEST_METHOD(GetNumeratorString_3) {
  355.         TFrac fracClass(0, 1);
  356.         string expectedNum = "0";
  357.         Assert::AreEqual(expectedNum, fracClass.getNumeratorString());
  358.     }
  359.     TEST_METHOD(GetDenominatorString_1) {
  360.         TFrac fracClass(1, 222);
  361.         string expectedNum = "222";
  362.         Assert::AreEqual(expectedNum, fracClass.getDenominatorString());
  363.     }
  364.     TEST_METHOD(GetDenominatorString_2) {
  365.         TFrac fracClass(-1, 222);
  366.         string expectedNum = "222";
  367.         Assert::AreEqual(expectedNum, fracClass.getDenominatorString());
  368.     }
  369.     TEST_METHOD(GetDenominatorString_3) {
  370.         TFrac fracClass(0, 1);
  371.         string expectedNum = "1";
  372.         Assert::AreEqual(expectedNum, fracClass.getDenominatorString());
  373.     }
  374.     TEST_METHOD(GetFractionString_1) {
  375.         TFrac fracClass(1, 2);
  376.         string expectedString = "1/2";
  377.         Assert::AreEqual(expectedString, fracClass.getFractionString());
  378.     }
  379.     TEST_METHOD(GetFractionString_2) {
  380.         TFrac fracClass(-1111, 9);
  381.         string expectedString = "-1111/9";
  382.         Assert::AreEqual(expectedString, fracClass.getFractionString());
  383.     }
  384.     TEST_METHOD(GetFractionString_3) {
  385.         TFrac fracClass(0, 1);
  386.         string expectedString = "0/1";
  387.         Assert::AreEqual(expectedString, fracClass.getFractionString());
  388.     }
  389.     TEST_METHOD(GetFractionString_4) {
  390.         TFrac fracClass(6666, 7779);
  391.         string expectedString = "2222/2593";
  392.         Assert::AreEqual(expectedString, fracClass.getFractionString());
  393.     }
  394.     };
  395. }
  396.  
RAW Paste Data