Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DiamondDogs.h"
- void testWhereInt1 ()
- {
- Stack<int> stack;
- Stack<int> res;
- stack.push(12);
- stack.push(3);
- stack.push(4);
- stack.push(0);
- stack.push(4);
- res.push(4);
- res.push(4);
- cout << "testWhereInt1 successful: " << boolalpha << (stack.where(WhereModInt1<int>()) == res) << endl;
- }
- void testWhereInt2 ()
- {
- Stack<int> stack;
- Stack<int> res;
- stack.push(12);
- stack.push(3);
- stack.push(4);
- stack.push(0);
- stack.push(1);
- res.push(3);
- res.push(1);
- cout << "testWhereInt2 successful: " << boolalpha << (stack.where(WhereModInt2<int>()) == res) << endl;
- }
- void testWhereInt3 ()
- {
- Stack<int> stack;
- Stack<int> res;
- stack.push(12);
- stack.push(-5);
- stack.push(4);
- stack.push(0);
- stack.push(10);
- res.push(-5);
- res.push(0);
- res.push(10);
- cout << "testWhereInt3 successful: " << boolalpha << (stack.where(WhereModInt3<int>()) == res) << endl;
- }
- void testWhereFloat1 ()
- {
- Stack<float> stack;
- Stack<float> res;
- stack.push(1.0002);
- stack.push(1.0);
- stack.push(4.021);
- stack.push(1.0);
- stack.push(4.021);
- res.push(1.0);
- res.push(1.0);
- cout << "testWhereFloat1 successful: " << boolalpha << (stack.where(WhereModFloat1<float>()) == res) << endl;
- }
- void testWhereFloat2 ()
- {
- Stack<float> stack;
- Stack<float> res;
- stack.push(1.0002);
- stack.push(1.0);
- stack.push(4.021);
- stack.push(2.0);
- stack.push(4.021);
- res.push(2.0);
- cout << "testWhereFloat2 successful: " << boolalpha << (stack.where(WhereModFloat2<float>()) == res) << endl;
- }
- void testWhereFloat3 ()
- {
- Stack<float> stack;
- Stack<float> res;
- stack.push(1.0002);
- stack.push(1.0);
- stack.push(4.021);
- stack.push(5.0);
- stack.push(4.021);
- res.push(1.0002);
- res.push(1.0);
- res.push(4.021);
- res.push(4.021);
- cout << "testWhereFloat3 successful: " << boolalpha << (stack.where(WhereModFloat3<float>()) == res) << endl;
- }
- void testWhereComplex1()
- {
- Stack<Complex> stack;
- Stack<Complex> res;
- stack.push(Complex (-1.12, -552.0));
- stack.push(Complex (0.0, 0.0));
- stack.push(Complex (10.12, 2.10));
- stack.push(Complex (22.0, 71.5));
- res.push(Complex (0.0, 0.0));
- res.push(Complex (10.12, 2.10));;
- cout << "testWhereComplex1 successful: " << boolalpha << (stack.where(WhereModComplex1<Complex>()) == res) << endl;
- }
- void testWhereComplex2()
- {
- Stack<Complex> stack;
- Stack<Complex> res;
- stack.push(Complex (-1.12, -552.0));
- stack.push(Complex (0.0, 0.0));
- stack.push(Complex (0.12, 0.222));
- stack.push(Complex (10.12, 2.10));
- stack.push(Complex (22.0, 71.5));
- res.push(Complex (-1.12, -552.0));
- res.push(Complex (10.12, 2.10));
- res.push(Complex (22.0, 71.5));
- cout << "testWhereComplex2 successful: " << boolalpha << (stack.where(WhereModComplex2<Complex>()) == res) << endl;
- }
- void testWhereComplex3()
- {
- Stack<Complex> stack;
- Stack<Complex> res;
- stack.push(Complex (-1.12, -552.0));
- stack.push(Complex (0.0, 0.0));
- stack.push(Complex (0.012, 0.099));
- stack.push(Complex (10.12, 2.10));
- stack.push(Complex (4.0, 3.0));
- res.push(Complex (0.0, 0.0));
- res.push(Complex (0.012, 0.099));
- cout << "testWhereComplex3 successful: " << boolalpha << (stack.where(WhereModComplex3<Complex>()) == res) << endl;
- }
- void testReduceInt1 ()
- {
- Stack<int> stack;
- int res = 23;
- stack.push(12);
- stack.push(3);
- stack.push(4);
- stack.push(0);
- stack.push(4);
- cout << "testReduceIntSum successful: " << boolalpha << (stack.reduce(Sum<int>()) == res) << endl;
- }
- void testReduceInt2 ()
- {
- Stack<int> stack;
- int res = 576;
- stack.push(12);
- stack.push(3);
- stack.push(4);
- stack.push(1);
- stack.push(4);
- cout << "testWhereIntMul successful: " << boolalpha << (stack.reduce(Mul<int>()) == res) << endl;
- }
- void testReduceFloat1 ()
- {
- Stack<float > stack;
- float res = 20.8;
- stack.push(12.1);
- stack.push(3.2);
- stack.push(4.0);
- stack.push(0.3);
- stack.push(1.2);
- cout << "testReduceFloatSum successful: " << boolalpha << (stack.reduce(Sum<float>()) == res) << endl;
- }
- void testReduceFloat2 ()
- {
- Stack<float > stack;
- float res = 154.88;
- stack.push(12.1);
- stack.push(3.2);
- stack.push(4.0);
- stack.push(1.0);
- stack.push(1.0);
- cout << "testReduceFloatMul successful: " << boolalpha << (stack.reduce(Mul<float>()) == res) << endl;
- }
- void testReduceComplex1 ()
- {
- Stack<Complex> stack;
- Complex res = Complex(15.0, 572.5);
- stack.push(Complex (-1.2, 0.3));
- stack.push(Complex (0.0, 0.0));
- stack.push(Complex (0.2, 552.2));
- stack.push(Complex (10.8, 10.0));
- stack.push(Complex (5.2, 10.0));
- cout << "testReduceComplexSum successful: " << boolalpha << (stack.reduce(Sum<Complex>()) == res) << endl;
- }
- void testReduceComplex2 () //bad
- {
- Stack<Complex> stack;
- Complex res = Complex(13.4784, 0.0);
- stack.push(Complex (-1.2, -552.0));
- stack.push(Complex (1.0, 0.0));
- stack.push(Complex (0.2, 552.2));
- stack.push(Complex (10.8, 10.0));
- stack.push(Complex (5.2, 10.0));
- cout << "testReduceComplexMul successful: " << boolalpha << !(stack.reduce(Mul<Complex>()) == res) << endl;
- }
- void testIndexOfInt()
- {
- Stack<int> stack;
- Stack<int> sub;
- size_t res = 2;
- stack.push(1);
- stack.push(2);
- stack.push(3);
- stack.push(4);
- stack.push(5);
- stack.push(6);
- sub.push(3);
- sub.push(4);
- size_t index = stack.indexOf(sub);
- cout << "testIndexOfInt successful: " << boolalpha << (index == res) << endl;
- }
- void testIndexOfFloat()
- {
- Stack<float> stack;
- Stack<float> sub;
- size_t res = 2;
- stack.push(1.4);
- stack.push(2.0);
- stack.push(3.6);
- stack.push(4.1);
- stack.push(5.9);
- stack.push(6.0);
- sub.push(3.6);
- sub.push(4.1);
- size_t index = stack.indexOf(sub);
- cout << "testIndexOfFloat successful: " << boolalpha << (index == res) << endl;
- }
- void testIndexOfComplex()
- {
- Stack<Complex> stack;
- Stack<Complex> sub;
- size_t res = 2;
- stack.push(Complex(1.22, 0.0));
- stack.push(Complex(-1.12, -552.0));
- stack.push(Complex(0.0, 0.0));
- stack.push(Complex(0.1, 0.9));
- stack.push(Complex(10.12, 2.10));
- stack.push(Complex(4.0, 3.0));
- sub.push(Complex(0.0, 0.0));
- sub.push(Complex(0.1, 0.9));
- size_t index = stack.indexOf(sub);
- cout << "testIndexOfComplex successful: " << boolalpha << (index == res) << endl;
- }
- void testAll ()
- {
- testWhereInt1();
- testWhereInt2();
- testWhereInt3();
- testWhereFloat1();
- testWhereFloat2();
- testWhereFloat3();
- testWhereComplex1();
- testWhereComplex2();
- testWhereComplex3();
- testReduceInt1();
- testReduceInt2();
- testReduceFloat1();
- testReduceFloat2();
- testReduceComplex1();
- testReduceComplex2();
- testIndexOfInt();
- testIndexOfFloat();
- testIndexOfComplex();
- }
- int main() {
- int oper, type, test;
- cout << "Hello, you are about to work with stacks. Would you like to test all functions?" << endl;
- cin >> test;
- while ((test != 1) && (test != 2)) {
- cout << "error (enter 1 or 2)" << endl;
- cin >> test;
- }
- if (test == 1) testAll();
- cout << "Choose the type of numbers: \n 1 - int\n 2 - float \n 3 - complex \n 4 - exit program" << endl;
- cin >> type;
- while ((type != 1) && (type != 2) && (type != 3) && (type != 4)) {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> type;
- }
- if (type == 1) //int
- {
- cout << "Choose an operation: \n 1 - where\n 2 - reduce\n 3 - find\n 4 - separate" << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4)) {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) {
- Stack<int> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- int x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - N mod 3 == 1\n 2 - N mod 2 == 1\n 3 - N mod 5 == 0" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- Stack<int> stackRes = stack.where(WhereModInt1<int>());
- cout << stackRes << endl;
- }
- break;
- case 2: {
- Stack<int> stackRes = stack.where(WhereModInt2<int>());
- cout << stackRes << endl;
- }
- break;
- case 3: {
- Stack<int> stackRes = stack.where(WhereModInt3<int>());
- cout << stackRes << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) {
- Stack<int> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- int x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - Sum\n 2 - Mul" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- int sum = stack.reduce(Sum<int>());
- cout << sum << endl;
- }
- break;
- case 2: {
- int mul = stack.reduce(Mul<int>());
- cout << mul << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) {
- Stack<int> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- int x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- Stack<int> sub;
- cout << "Enter sub stack size:" << endl;
- size_t sizeSub;
- cin >> sizeSub;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < sizeSub; i++) {
- int x;
- cin >> x;
- sub.push(x);
- }
- cout << "Your sub stack: " << sub << endl;
- bool contain = stack.contains(sub);
- size_t index = stack.indexOf(sub);
- cout << boolalpha << contain << endl;
- cout <<"Index found: " << index << endl;
- } else if (oper == 4) {
- Stack<int> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- int x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - N mod 3 == 1\n 2 - N mod 2 == 1\n 3 - N mod 5 == 0" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- pair<Stack<int>, Stack<int>> my_pair = stack.split(WhereModInt1<int>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 2: {
- pair<Stack<int>, Stack<int>> my_pair = stack.split(WhereModInt2<int>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 3: {
- pair<Stack<int>, Stack<int>> my_pair = stack.split(WhereModInt3<int>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- }
- } else if (type == 2) {
- cout << "Choose an operation: \n 1 - where\n 2 - reduce\n 3 - find\n 4 - separate" << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4)) {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) {
- Stack<float> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- float x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - N == 1\n 2 - N == 2\n 3 - N != 5" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- Stack<float> stackRes = stack.where(WhereModFloat1<float>());
- cout << stackRes << endl;
- }
- break;
- case 2: {
- Stack<float> stackRes = stack.where(WhereModFloat2<float>());
- cout << stackRes << endl;
- }
- break;
- case 3: {
- Stack<float> stackRes = stack.where(WhereModFloat3<float>());
- cout << stackRes << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) {
- Stack<float> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- float x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - Sum\n 2 - Mul" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- float sum = stack.reduce(Sum<float>());
- cout << sum << endl;
- }
- break;
- case 2: {
- float mul = stack.reduce(Mul<float>());
- cout << mul << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) {
- Stack<float> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- float x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- Stack<float> sub;
- cout << "Enter sub stack size:" << endl;
- size_t sizeSub;
- cin >> sizeSub;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < sizeSub; i++) {
- float x;
- cin >> x;
- sub.push(x);
- }
- cout << "Your sub stack: " << sub << endl;
- bool contain = stack.contains(sub);
- size_t index = stack.indexOf(sub);
- cout << boolalpha << contain << endl;
- cout <<"Index found: " << index << endl;
- } else if (oper == 4) {
- Stack<float> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- float x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - N == 1\n 2 - N == 2\n 3 - N != 5" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- pair<Stack<float>, Stack<float>> my_pair = stack.split(WhereModFloat1<float>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 2: {
- pair<Stack<float>, Stack<float>> my_pair = stack.split(WhereModFloat2<float>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 3: {
- pair<Stack<float>, Stack<float>> my_pair = stack.split(WhereModFloat3<float>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- }
- } else if (type == 3) //complex
- {
- cout << "Choose an operation: \n 1 - where\n 2 - reduce\n 3 - find\n 4 - separate" << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4)) {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) {
- Stack<Complex> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- Complex x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - |Z| < 64 \n 2 - |Z| > 4\n 3 - |Z| > 1" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- Stack<Complex> stackRes = stack.where(WhereModComplex1<Complex>());
- cout << stackRes << endl;
- }
- break;
- case 2: {
- Stack<Complex> stackRes = stack.where(WhereModComplex2<Complex>());
- cout << stackRes << endl;
- }
- break;
- case 3: {
- Stack<Complex> stackRes = stack.where(WhereModComplex3<Complex>());
- cout << stackRes << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) {
- Stack<Complex> stack;
- cout << "Enter stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- Complex x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - Sum\n 2 - Mul" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- Complex sum = stack.reduce(Sum<Complex>());
- cout << sum << endl;
- }
- break;
- case 2: {
- Complex mul = stack.reduce(Mul<Complex>());
- cout << mul << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) {
- Stack<Complex> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- Complex x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- Stack<Complex> sub;
- cout << "Enter sub stack size:" << endl;
- size_t sizeSub;
- cin >> sizeSub;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < sizeSub; i++) {
- Complex x;
- cin >> x;
- sub.push(x);
- }
- cout << "Your sub stack: " << sub << endl;
- bool contain = stack.contains(sub);
- size_t index = stack.indexOf(sub);
- cout << boolalpha << contain << endl;
- cout <<"Index fount: " << index << endl;
- } else if (oper == 4) {
- Stack<Complex> stack;
- cout << "Enter main stack size:" << endl;
- size_t size;
- cin >> size;
- cout << "Enter elements:" << endl;
- for (int i = 0; i < size; i++) {
- Complex x;
- cin >> x;
- stack.push(x);
- }
- cout << "Your stack: " << stack << endl;
- cout << "Choose your function: \n 1 - |Z| < 64 \n 2 - |Z| > 4\n 3 - |Z| < 1" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- pair<Stack<Complex>, Stack<Complex>> my_pair = stack.split(WhereModComplex1<Complex>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 2: {
- pair<Stack<Complex>, Stack<Complex>> my_pair = stack.split(WhereModComplex2<Complex>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- case 3: {
- pair<Stack<Complex>, Stack<Complex>> my_pair = stack.split(WhereModComplex3<Complex>());
- cout << "first stack: " << my_pair.first << endl;
- cout << "second stack: " << my_pair.second << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- }
- } else if (type == 4) {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement