diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a50e8e7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4a9efca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/js/Desktop/caschenrechner/src/test/c", + "program": "/home/js/Desktop/caschenrechner/src/test/c/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f168e7d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "C_Cpp.errorSquiggles": "disabled", + "files.associations": { + "testforoperator.h": "c", + "testfornumber.h": "c", + "programmingmode.h": "c" + }, + "C_Cpp_Runner.msvcBatchPath": "" +} \ No newline at end of file diff --git a/Unity b/Unity new file mode 160000 index 0000000..134496c --- /dev/null +++ b/Unity @@ -0,0 +1 @@ +Subproject commit 134496c6c0c34b463d58daef1904a12abdc5c8e0 diff --git a/project.yml b/project.yml index 4801bd7..2682e52 100644 --- a/project.yml +++ b/project.yml @@ -91,6 +91,7 @@ :system: - m # Example: add 'm' to use the math library :test: +<<<<<<< HEAD - stdio - string - stdlib @@ -100,6 +101,17 @@ - string - stdlib - m # Example: add 'm' to use the math library in release builds +======= + #- stdio + #- string + #- stdlib + #- m # Example: add 'm' to use the math library in tests + :release: + #- stdio + #- string + #- stdlib + #- m # Example: add 'm' to use the math library in release builds +>>>>>>> develop :plugins: :load_paths: diff --git a/src/main/c/BasicMode.c b/src/main/c/BasicMode.c new file mode 100644 index 0000000..4cbef65 --- /dev/null +++ b/src/main/c/BasicMode.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include "BasicMode.h" + + +// convert decimal to binary +long long int DecToBin(long long int n) { + long long int bin = 0; + long long int rem, i = 1; + + while (n != 0) { + rem = n % 2; + bin += rem * i; + i *= 10; + n /= 2; + } + + return bin; +} +// convert binary to decimal +long long int BinToDec(long long int n) { + long long int dec = 0, i = 0, rem; + + while (n != 0) { + rem = n % 10; + dec += rem * pow(2, i); + i++; + n /= 10; + } + + return dec; +} +//addition +long long int additionbin(long long int a, long long int b) { + long long int dec1, dec2; + dec1 = BinToDec(a); + dec2 = BinToDec(b); + dec1 = dec1 + dec2; + dec2 = DecToBin(dec1); + + return dec2; +} +// multiplication +long long int multiplicationbin(long long int a, long long int b) { + long long int dec1, dec2; + dec1 = BinToDec(a); + dec2 = BinToDec(b); + dec1 = dec1 * dec2; + dec2 = DecToBin(dec1); + + return dec2; +} +//subtraction +long long int subtractionbin(long long int a, long long int b) { + long long int dec1, dec2; + dec1 = BinToDec(a); + dec2 = BinToDec(b); + dec1 = dec1 - dec2; + dec2 = DecToBin(dec1); + + return dec2; +} + + diff --git a/src/main/c/BasicMode.h b/src/main/c/BasicMode.h new file mode 100644 index 0000000..dfee843 --- /dev/null +++ b/src/main/c/BasicMode.h @@ -0,0 +1,10 @@ +#ifndef BasicMode +#define BasicMode + +long long int DecToBin(long long int n); +long long int BinToDec(long long int n); +long long int additionbin(long long int a, long long int b); +long long int multiplicationbin(long long int a, long long int b); +long long int subtractionbin(long long int a, long long int b); + +#endif // BasicMode diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c new file mode 100644 index 0000000..23d808d --- /dev/null +++ b/src/main/c/ConvertMode.c @@ -0,0 +1,258 @@ +#include +#include +#include +#include +#include + +// Unit converter mode + +int choice, startingUnit, endingUnit; +double value, result; + +char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; +char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'}; +char Fluid[] = { 'ml', 'l' , 'gallon'}; +char Temp[] = { 'celsius', 'fahrenheit' }; +char Speed[] = { 'km/h','mp/h' }; +char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; +char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y'}; +char currency[] = { 'E', 'D', 'R' }; + + +double getValue(int choice) { + printf("\nEnter the value to be converted: "); + scanf("%lf", &value); + + while (choice < 0 && choice >= 15) { + switch (choice) + { + case 1: + printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m, 3 km): "); + scanf("%d", &startingUnit); + //1 10 1.000 1.000.000 + printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m, 3 km): "); + scanf("%d", &endingUnit); + + result = ConMeter(value, startingUnit,endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 2: + printf("\nEnter what the Unit is starting with (0 feet/Inch, 1 meter): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 feet/Inch, 1 meter): "); + scanf("%d", &endingUnit); + + result = ConMeterToFoot(value, startingUnit, endingUnit); + + if (endingUnit == 0) { //if feet/inch change to 4. in array of Distance + endingUnit = 4; + } + + else if (endingUnit == 1) { //if meter change to 2. in array of Distance + endingUnit = 2; + } + + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 3: + printf("\nEnter what the Unit is starting with (0 miles, 1 kilometer): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 miles, 1 kilometer): "); + scanf("%d", &endingUnit); + + result = ConKilometerToMiles(value, startingUnit, endingUnit); + + if (endingUnit == 0) { //if miles change to 5. in array of Distance + endingUnit = 5; + } + + else if (endingUnit == 1) { //if kilometer change to 2. in array of Distance + endingUnit = 3; + } + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 4://'mg', 'g', 'kg', 't' + printf("\nEnter what the Unit is starting with (0 mg, 1 g, 2 kg , 3 t): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 mg, 1 g, 2 kg , 3 t): "); + scanf("%d", &endingUnit); + + result = ConGram(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Weight[endingUnit]); + break; + + case 5://'kg', 'pounds' + printf("\nEnter what the Unit is starting with (0 kg, 1 pounds): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 kg, 1 pounds): "); + scanf("%d", &endingUnit); + + result = ConGramToPounds(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Weight[endingUnit]); + break; + + case 6://'celsius', 'fahrenheit' + printf("\nEnter what the Unit is starting with (0 celsius, 1 fahrenheit): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 celsius, 1 fahrenheit): "); + scanf("%d", &endingUnit); + + result = ConTemp(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Temp[endingUnit]); + break; + + case 7://'km/h','mp/h' + printf("\nEnter what the Unit is starting with (0 km/h, 1 mp/h): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 km/h, 1 mp/h): "); + scanf("%d", &endingUnit); + + result = ConSpeed(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]); + break; + + case 8://'ml', 'l' + printf("\nEnter what the Unit is starting with (0 ml, 1 l): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 ml, 1 l): "); + scanf("%d", &endingUnit); + + result = ConLiter(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); + break; + + + case 9://'ml', 'l' + printf("\nEnter what the Unit is starting with (0 l, 1 gallon): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 l, 1 gallon): "); + scanf("%d", &endingUnit); + + result = ConLiterToGallon(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); + break; + + case 10://char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; + printf("\nEnter what the Unit is starting with (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): "); + scanf("%d", &endingUnit); + + result = ConData(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]); + break; + + case 11://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; + printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &endingUnit); + + result = ConArea(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 12://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; + printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): "); + scanf("%d", &endingUnit); + + result = ConArea(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 13://char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' }; + printf("\nEnter what the Unit is starting with (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): "); + scanf("%d", &endingUnit); + + result = ConTime(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + + case 14: + printf("\nEnter what the Unit is starting with (0 (24h), 1 (12h)): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 (24h), 1 (12h)): "); + scanf("%d", &endingUnit); + + result = ConClock(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; + } + } +} + +void unitConverterMode() { + + printf("Unit Converter Mode:\n"); + + printf("Distance conversions:\n"); + printf("1. Convert Meter (cm, m, km)\n"); + printf("2. Meter to foot/inches\n"); + printf("3. Kilometer to Miles\n"); + + printf("Weight conversion:\n"); + printf("4. Convert Gram (mg, g, kg)\n"); + printf("5. Gram to Pounds \n"); + + printf("Temprature conversion:\n"); + printf("6. Celsius to Fahrenheit\n"); + + printf("Speed conversion:\n"); + printf("7. km/h to mph \n"); + + printf("Fluid conversion:\n"); + printf("8. Convert Liter (ml, l, kl) \n"); + printf("9. Liter to Gallon\n"); + + printf("Data conversions:\n"); + printf("10. Convert Data size (MB, GB, TB)\n"); + + printf("Area/Volume conversions \n"); + printf("11. Convert area (cm, m, km) \n"); + printf("12. Convert Volume (cm, m, km)\n"); + + printf("Time conversion \n"); + printf("13. Convert time (s, m, h, d, w, m, y) \n"); + printf("14. Convert Clock (12 Hour, 24 Hour) \n"); + + printf("Time conversion \n"); + printf("15. Convert currency (Euro, Dollar, Russian Rubel) \n"); + + printf("\nEnter your choice (Exit with 0): "); + scanf("%d", &choice); + getValue(choice); +} diff --git a/src/main/c/main_calculator.c b/src/main/c/main_calculator.c index 013714e..99ee7c6 100644 --- a/src/main/c/main_calculator.c +++ b/src/main/c/main_calculator.c @@ -1,12 +1,1356 @@ -#include -// #include + +#include #include +#include + +#include "main_calculator.h" + + +double add(double a, double b) { + return a + b; +} + +double minus (double a, double b){ + return a - b; +} + +double multiply(double a, double b) { + return a * b; +} + +double divide(double a, double b) { + if (b == 0) { + return 0; + } + return a / b; +} + +// Square root function +double squareRootFunction(double x) { + // Using the sqrt function from math.h + return sqrt(x); +} + +//.. +// Trigonometric functions +double sineFunction(double angle) { + // Convert degrees to radians for trigonometric functions + return sin(angle * M_PI / 180.0); +} + + +double cosineFunction(double angle) { + // Convert degrees to radians for trigonometric functions + return cos(angle * M_PI / 180.0); +} + +double tangentFunction(double angle) { + // Convert degrees to radians for trigonometric functions + return tan(angle * M_PI / 180.0); +} + +//.. +// Logarithmic functions +double logarithmFunction(double x) { + // Logarithm with base 10 + return log10(x); +} + +double naturalLogarithmFunction(double x) { + // Natural logarithm (ln) + return log(x); +} + +double logarithmBase2Function(double x) { + // Logarithm with base 2 + return log2(x); +} +//.. +// Exponential function +double exponentialFunction(double x) { + // Exponential function (e^x) + return exp(x); +} + +// .. +// Bitwise AND function +int bitwiseAND(int num1, int num2) { + return num1 & num2; +} + +// Bitwise OR function +int bitwiseOR(int num1, int num2) { + return num1 | num2; +} + +// Bitwise XOR function +int bitwiseXOR(int num1, int num2) { + return num1 ^ num2; +} + +//Conversion Functions +double ConMeter(double meter, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return meter; + break; + + case 1: //0.1cm + return meter / 10; + break; + + case 2: //0.001m + return meter / 1000; + break; + + case 3: //0.000001km + return meter / 1000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //10 + return meter * 10; + break; + + case 1: //1 + return meter; + break; + + case 2: //0.01 + return meter / 100; + break; + + case 3: //0.00001 + return meter / 100000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //1000 + return meter * 1000; + break; + + case 1: //100 + return meter * 100; + break; + + case 2: //1 + return meter; + break; + + case 3: //0.001 + return meter / 1000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000 + return meter * 1000000; + break; + + case 1: // 100000 + return meter * 100000; + break; + + case 2: // 1000 m + return meter * 1000; + break; + + case 3: //1 km + return meter; + break; + + default: + break; + } + + default: + break; + } +} + +double ConArea(double area, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return area; + break; + + case 1: //0.01cm + return area / 100; + break; + + case 2: //0.000001m + return area / 1000000; + break; + + case 3: //0.000000000001km + return area / 1000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //100 + return area * 100; + break; + + case 1: //1 + return area; + break; + + case 2: //0.0001 + return area / 10000; + break; + + case 3: //0.0000000001 + return area / 10000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //1000000 + return area * 1000000; + break; + + case 1: //10000 + return area * 10000; + break; + + case 2: //1 + return area; + break; + + case 3: //0.000001 + return area / 1000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000 + return area * 1000000000000; + break; + + case 1: // 10000000000 + return area * 10000000000; + break; + + case 2: // 1000000 m + return area * 1000000; + break; + + case 3: //1 km + return area; + break; + + default: + break; + } + + default: + break; + } +} + +double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //feet/inch to x + switch (endingUnit) + { + case 0: //feet/inch to feet/inch + return distance; + break; + + case 1: //feet/inch to meter + return distance / 3.28084; + break; + + default: + break; + } + + case 1: //meter to x + switch (endingUnit) + { + case 0: //meter to feet/inch + return distance * 3.28084; + break; + + case 1: //feet/inch to feet/inch + return distance; + break; + + default: + break; + } + + default: + break; + } +} + +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //miles to x + switch (endingUnit) + { + case 0: //miles to miles + return distance; + break; + + case 1: //miles to kilometer + return distance * 1.60934; + break; + + default: + break; + } + + case 1: //kilometer to x + switch (endingUnit) + { + case 0: //kilometer to miles + return distance / 1.60934; + break; + + case 1: //kilometer to kilometer + return distance; + break; + + default: + break; + } + + default: + break; + } +} + +double ConGram(double weight, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'mg', 'g', 'kg', 't' + case 0: //mg to x + switch (endingUnit) + { + case 0: //1 + return weight; + break; + + case 1: //0.001 + return weight / 1000; + break; + + case 2: //0.000001 + return weight / 1000000; + break; + + case 3: //0.000000001 + return weight / 1000000000; + break; + + default: + break; + } + + case 1: //g to x + switch (endingUnit) + { + case 0: //1000 + return weight * 1000; + break; + + case 1: //1 + return weight; + break; + + case 2: //0.01 + return weight / 100; + break; + + case 3: //0.000001 + return weight / 100000; + break; + + default: + break; + } + + case 2: //kg to x + switch (endingUnit) + { + case 0: //1000 + return weight * 1000; + break; + + case 1: //100 + return weight * 100; + break; + + case 2: //1 + return weight; + break; + + case 3: //0.001 + return weight / 1000; + break; + + default: + break; + } + + case 3://t to x + switch (endingUnit) + { + case 0: // 1000000000 + return weight * 1000000; + break; + + case 1: // 1000000 + return weight * 100000; + break; + + case 2: // 1000 + return weight * 1000; + break; + + case 3: //1 + return weight; + break; + + default: + break; + } + + default: + break; + } +} + +double ConGramToPounds(double weight, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kg to x + switch (endingUnit) + { + case 0: //kg to pounds + return weight *= 2.20462; + break; + + case 1: //kg to kg + return weight; + break; + + default: + break; + } + + case 1: //pounds to x + switch (endingUnit) + { + case 0: //pounds to kg + return weight *= 453.592; + break; + + case 1: //pounds to pounds + return weight; + break; + + default: + break; + } + + default: + break; + } +} + +double ConTemp(double temp, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //celsius to x + switch (endingUnit) + { + case 0: //celsius to fahrenheit + return temp = (temp - 32) * 0,55555555; + break; + + case 1: //celsius to celsius + return (temp * 9 / 5) + 32; + break; + + default: + break; + } + + case 1: //fahrenheit to x + switch (endingUnit) + { + case 0: //fahrenheit to celsius + return temp = (temp * 1, 8) + 32; + break; + + case 1: //fahrenheit to fahrenheit + return temp; + break; + + default: + break; + } + + default: + break; + } +} + +double ConSpeed(double speed, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kmh to x + switch (endingUnit) + { + case 0: //kmh to kmh + return speed; + break; + + case 1: //kmh to mph + return speed / 1.60934; + break; + + default: + break; + } + + case 1: //mph to x + switch (endingUnit) + { + case 0: //mph to kmh + return speed * 1.60934; + break; + + case 1: //mph to mph + return speed; + break; + + default: + break; + } + + default: + break; + } +} + +double ConLiter(double liter, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //ml to x + switch (endingUnit) + { + case 0: //ml to ml + return liter; + break; + + case 1: //ml to l + return ( liter / 1000 ); + break; + + default: + break; + } + + case 1: //l to x + switch (endingUnit) + { + case 0: //l to ml + return liter * 1000; + break; + + case 1: //l to l + return liter; + break; + + default: + break; + } + + default: + break; + } +} + +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //l to x + switch (endingUnit) + { + case 0: //l to l + return fluid; + break; + + case 1: //l to gallon + return fluid / 3.785; + break; + + default: + break; + } + + case 1: //gallon to x + switch (endingUnit) + { + case 0: //gallon to l + return fluid * 3.78541; + break; + + case 1: //gallon to gallon + return fluid; + break; + + default: + break; + } + + default: + break; + } +} + +double ConData(double data, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'B', 'KB', 'MB', 'GB', 'TB', 'PT' + case 0: //B to x + switch (endingUnit) + { + case 0: //1 + return data; + break; + + case 1: //0.001 + return data / 1000; + break; + + case 2: //0.000001 + return data / 1000000; + break; + + case 3: //0.000000001 + return data / 1000000000; + break; + + case 4: //0.000000000001 + return data / 1000000000000; + break; + + case 5: //0.000000000000001 + return data / 1000000000000000; + break; + + default: + break; + } + + case 1: //KB to x + switch (endingUnit) + { + case 0: //1000 + return data * 1000; + break; + + case 1: //1 + return data; + break; + + case 2: //0.001 + return data / 1000; + break; + + case 3: //0.000001 + return data / 1000000; + break; + + case 4: //0.000000001 + return data / 1000000000; + break; + + case 5: //0.000000000001 + return data / 1000000000000; + break; + + default: + break; + } + + case 2: //MB to x + switch (endingUnit) + { + case 0: //0.000001 + return data * 1000000; + break; + + case 1: //0.001 + return data * 1000; + break; + + case 2: //1 + return data; + break; + + case 3: //0.001 + return data / 1000; + break; + + case 4: //0.000001 + return data / 1000000; + break; + + case 5: //0.000000001 + return data / 1000000000; + break; + + default: + break; + } + + + case 3: //GB to x + switch (endingUnit) + { + case 0: //0.000000001 + return data * 1000000000; + break; + + case 1: //0.000001 + return data * 1000000; + break; + + case 2: //1000 + return data * 1000;; + break; + + case 3: //1 + return data; + break; + + case 4: //0.001 + return data / 1000; + break; + + case 5: //0.000001 + return data / 1000000; + break; + + default: + break; + } + + + case 4: //TB to x + switch (endingUnit) + { + case 0: //0.000000000001 + return data * 1000000000000; + break; + + case 1: //0.000000001 + return data * 1000000000; + break; + + case 2: //1000000 + return data * 1000000;; + break; + + case 3: //1000 + return data * 1000; + break; + + case 4: //1 + return data; + break; + + case 5: //0.001 + return data / 1000; + break; + + default: + break; + } + + + case 5: //PB to x + switch (endingUnit) + { + case 0: //0.000000000000001 + return data * 1000000000000000; + break; + + case 1: //0.000000000001 + return data * 1000000000000; + break; + + case 2: //1000000000 + return data * 1000000000;; + break; + + case 3: //1000000 + return data * 1000000; + break; + + case 4: //1000 + return data * 1000; + break; + + case 5: //1 + return data; + break; + + default: + break; + } + } +} + +double ConVolume(double volum, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return volum; + break; + + case 1: //0.001cm + return volum / 1000; + break; + + case 2: //0.000000001m + return volum / 1000000000; + break; + + case 3: //0.000000000000001km + return volum / 1000000000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //1000 + return volum * 1000; + break; + + case 1: //1 + return volum; + break; + + case 2: //0.000001 + return volum / 1000000; + break; + + case 3: //0.0000000000001 + return volum / 1000000000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //100000000 + return volum * 1000000000; + break; + + case 1: //1000000 + return volum * 1000000; + break; + + case 2: //1 + return volum; + break; + + case 3: //0.000000001 + return volum / 1000000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000000000 + return volum * 1000000000000000000; + break; + + case 1: // 1000000000000000 + return volum * 1000000000000000; + break; + + case 2: // 1000000000 m + return volum * 1000000000; + break; + + case 3: //1 km + return volum; + break; + + default: + break; + } + + default: + break; + } +} +double ConClock(double time, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //24 to x + switch (endingUnit) + { + case 0: //24 to 24 + return time; + break; + + case 1: //24 to 12 + if (time > 12) { + return time - 12; + } + + else { + return time; + } + break; + + default: + break; + } + + case 1: //12 to x + switch (endingUnit) + { + case 0: //12 to 24 + return time + 12; + break; + + case 1: //12 to 12 + return time; + break; + + default: + break; + } + + default: + break; + } +} + +double ConTime(double time, int startingUnit, int endingUnit) { + switch (startingUnit) + {//'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' + case 0: //ms to x + switch (endingUnit) + { + case 0: //ms + return time; + break; + + case 1: //s + return (double) time / 1000; + break; + + case 2: //min + return (double) time / (1000 * 60); + break; + + case 3: //h + return (double) time / (1000 * 60 * 60); + break; + + case 4: //d + return (double) time / (1000 * 60 * 60 * 24); + break; + + case 5: //w + return (double) time / (1000 * 60 * 60 * 24 * 7); + break; + + case 6: //mon + return time / (1000.0 * 60.0 * 60.0 * 24.0 * 7.0 * 30.0); + break; + + case 7: //y + return time / (1000.0 * 60.0 * 60.0 * 24.0 * 7.0 * 30.0 * 12.0); + break; + + default: + break; + } + + case 1: //s to x + switch (endingUnit) + { + case 0: //ms + return time * 1000; + break; + + case 1: //s + return time; + break; + + case 2: //min + return time / 60; + break; + + case 3: //h + return time / (60 * 60); + break; + + case 4: //d + return time / (60 * 60 * 24); + break; + + case 5: //w + return time / (60 * 60 * 24 * 7); + break; + + case 6: //mon + return time / (60 * 60 * 24 * 7 * 30); + break; + + case 7: //y + return time / (60 * 60 * 24 * 7 * 30 * 12); + break; + + default: + break; + } + + case 2: //min to x + switch (endingUnit) + { + case 0: //ms + return time * 1000; + break; + + case 1: //s + return time * 1000 * 60; + break; + + case 2: //min + return time; + break; + + case 3: //h + return time / 60; + break; + + case 4: //d + return time / (60 * 24); + break; + + case 5: //w + return time / (60 * 24 * 7); + break; + + case 6: //mon + return time / (60 * 24 * 7 * 4); + break; + + case 7: //y + return time / (60 * 24 * 7 * 4 * 12); + break; + + default: + break; + } + + case 3: //h to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60; + break; + + case 1: //s + return time * 60 * 60; + break; + + case 2: //min + return time * 60; + break; + + case 3: //h + return time; + break; + + case 4: //d + return time / 24; + break; + + case 5: //w + return time / (24 * 7); + break; + + case 6: //mon + return time / (24 * 7 * 4); + break; + + case 7: //y + return time / (24 * 7 * 4 * 12); + break; + + default: + break; + } + + case 4: //d to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24; + break; + + case 1: //s + return time * 60 * 60 * 24; + break; + + case 2: //min + return time * 60 * 24; + break; + + case 3: //h + return time * 24; + break; + + case 4: //d + return time; + break; + + case 5: //w + return time / 7; + break; + + case 6: //mon + return time / (7 * 4); + break; + + case 7: //y + return time / (7 * 4 * 12); + break; + + default: + break; + } + + case 5: //w to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7; + break; + + case 2: //min + return time * 60 * 24 * 7; + break; + + case 3: //h + return time * 24 * 7; + break; + + case 4: //d + return time * 7; + break; + + case 5: //w + return time; + break; + + case 6: //mon + return time / 4; + break; + + case 7: //y + return time / (4 * 12); + break; + + default: + break; + } + + case 6: //mon to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7 * 4; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7 * 4; + break; + + case 2: //min + return time * 60 * 24 * 7 * 4; + break; + + case 3: //h + return time * 24 * 7 * 4; + break; + + case 4: //d + return time * 7 * 4; + break; + + case 5: //w + return time * 4; + break; + + case 6: //mon + return time; + break; + + case 7: //y + return time / 12; + break; + + default: + break; + } + + case 7: //y to x + switch (endingUnit) + { + case 0: //ms + return time * 1000 * 60 * 60 * 24 * 7 * 4 * 12; + break; + + case 1: //s + return time * 60 * 60 * 24 * 7 * 4 * 12; + break; + + case 2: //min + return time * 60 * 24 * 7 * 4 * 12; + break; + + case 3: //h + return time * 24 * 7 * 4 * 12; + break; + + case 4: //d + return time * 7 * 4 * 12; + break; + + case 5: //w + return time * 4 * 12; + break; + + case 6: //mon + return time * 12; + break; + + case 7: //y + return time; + break; + //(1000 * 60 * 60 * 24 * 7 * 4 * 12) + default: + break; + } + } +} + + +// change mode +int mode(int userChoice){ + + switch(userChoice) { + + case 1:return 1; // Basic mode + break; + + case 2:return 2; // Scientific mode (Trigonomertic functions, Logarithm and exponential functions.) + break; + + case 3:return 3; // Graph mode (Draw and visualize functions.) + break; + + case 4:return 4; // Programming mode (Binary , octal and hexadecimal ) + break; + + case 5:return 5; // Unit converter mode (length, weight volume etc.) + break; + + case 0: return 0; // printf("Exiting the calculator.\n"); + break; + + default: return -1; // printf("Invalid choice. Please try again.\n"); + + } + +} + + +// display the mode options: +int displayMenu(){ -#include "calculator.h" + printf("\nCalculator Modes: \n"); + printf("\n1: Basic Mode\n"); + printf("\n2: Scientific Mode (Trigonomertic functions, Logarithm and exponential functions.)\n"); + printf("\n3: Graph Mode (Draw and visualize functions.)\n"); + printf("\n4: Programming Mode (Binary , octal and hexadecimal )\n"); + printf("\n5: Unit converter Mode (length, weight volume etc.)\n"); + printf("\n0: Exit calculator\n"); + return 1; // return 1 to check if the function works -int add(int a, int b) { - - return a+b; - } diff --git a/src/main/c/main_calculator.h b/src/main/c/main_calculator.h new file mode 100644 index 0000000..45cb01e --- /dev/null +++ b/src/main/c/main_calculator.h @@ -0,0 +1,83 @@ +#ifndef MAIN_CALCULATOR +#define MAIN_CALCULATOR + +// add function +double add(double a, double b); + +// minus function +double minus(double a, double b); + +// multiply function +double multiply(double a, double b); + +// divide function +double divide(double a, double b); + +// Square root function +double squareRootFunction(double x); + +//.. +// Trigonometric functions +double sineFunction(double angle); + +double cosineFunction(double angle); + +double tangentFunction(double angle); + +//.. +// Logarithmic functions +double logarithmFunction(double x); + +double naturalLogarithmFunction(double x); + +double logarithmBase2Function(double x); + +//.. +// Exponential function +double exponentialFunction(double x); + +// .. +// Bitwise AND function +int bitwiseAND(int num1, int num2); + +// Bitwise OR function +int bitwiseOR(int num1, int num2); + +// Bitwise XOR function +int bitwiseXOR(int num1, int num2); + +int mode(int userChoice); + +int displayMenu(); + +// Conversion Functions +double ConMeter(double meter, int startingUnit, int endingUnit); + +double ConMeterToFoot(double distance, int startingUnit, int endingUnit); + +double ConKilometerToMiles(double distance, int startingUnit, int endingUnit); + +double ConGram(double weight, int startingUnit, int endingUnit); + +double ConGramToPounds(double weight, int startingUnit, int endingUnit); + +double ConTemp(double temp, int startingUnit, int endingUnit); + +double ConSpeed(double speed, int startingUnit, int endingUnit); + +double ConLiter(double liter, int startingUnit, int endingUnit); + +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); + +double ConData(double data, int startingUnit, int endingUnit); + +double ConArea(double area, int startingUnit, int endingUnit); + +double ConVolume(double volum, int startingUnit, int endingUnit); + +double ConClock(double time, int startingUnit, int endingUnit); + +double ConTime(double time, int startingUnit, int endingUnit); + + +#endif // CALCULATOR \ No newline at end of file diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c new file mode 100644 index 0000000..7457a95 --- /dev/null +++ b/src/main/c/programmingMode.c @@ -0,0 +1,99 @@ +// programmingMode + +#include +#include + +#include "programmingMode.h" + + +// Function to convert an integer to binary representation +char* binaryRepresentation(int num); + +// get the NUmbers from the user +int getIntegerInput(const char* prompt) { + int num; + printf("%s", prompt); + scanf("%d", &num); + return num; +} + +// Display the diffrent operations and scan them +char getOperatorInput() { + char operator; + printf("Enter operator (+, -, *, /): "); + scanf(" %c", &operator); + return operator; +} + +// Calculation +int performOperation(int num1, char operatorType, int num2) { + switch (operatorType) { + case '+': + return num1 + num2; + case '-': + return num1 - num2; + case '*': + return num1 * num2; + case '/': + if (num2 != 0) { + return num1 / num2; + } else { + return 0; + } + default: + printf("Invalid operator\n"); + return 0; + } +} + +void programmingMode() { + +char choice; + do { + int num1 = getIntegerInput("Enter first integer: "); + char operator = getOperatorInput(); + int num2 = getIntegerInput("Enter second integer: "); + + // Calculation + int result = performOperation(num1, operator, num2); + + // Display the result in different bases based on user choice + int base; + printf("Choose base to print the result (2 for binary, 8 for octal, 16 for hexadecimal): "); + scanf("%d", &base); + + switch (base) { + case 2: + printf("Result (Binary): %s\n", binaryRepresentation(result)); + break; + case 8: + printf("Result (Octal): %o\n", result); + break; + case 16: + printf("Result (Hexadecimal): %x\n", result); + break; + default: + printf("Invalid base choice\n"); + break; + } + + // Ask user if they want to continue + printf("Do you want to continue? (y/n): "); + scanf(" %c", &choice); + + } while (choice == 'y' || choice == 'Y'); +} + + + +// Function to convert an integer to binary representation +char* binaryRepresentation(int num) { + static char binary[32]; + for (int i = 31; i >= 0; i--) { + binary[i] = (num & 1) + '0'; + num >>= 1; + } + binary[32] = '\0'; + return binary; +} + diff --git a/src/main/c/programmingMode.h b/src/main/c/programmingMode.h new file mode 100644 index 0000000..4e800e4 --- /dev/null +++ b/src/main/c/programmingMode.h @@ -0,0 +1,8 @@ +#ifndef PROGRAMMINGMODE +#define PROGRAMMINGMODE + +// to test some calculations +int performOperation(int num1, char operatorType, int num2); + + +#endif // PROGRAMMINGMODE \ No newline at end of file diff --git a/src/main/c/scientificMode.c b/src/main/c/scientificMode.c new file mode 100644 index 0000000..2dd40d8 --- /dev/null +++ b/src/main/c/scientificMode.c @@ -0,0 +1,156 @@ +// scientificMode + +#include +#include + +// get the number which has to be calculated +double getNumberFromUser() { + double num; + printf("Enter a number: "); + scanf("%lf", &num); + return num; +} + +// Choice for ScientificMode +int getScientificModeChoice() { + int choice; + printf("Scientific mode Options:\n"); + printf("1: Square root\n"); + printf("2: Exponential\n"); + printf("3: Logarithm\n"); + printf("4: Trigonometric\n"); + printf("0: Exit\n"); + scanf("%d", &choice); + return choice; +} + +// Choice for Logarithm +int getLogarithmChoice() { + int logChoice; + printf("Logarithm Options:\n"); + printf("1: Logarithm (base 10)\n"); + printf("2: Natural Logarithm (ln)\n"); + printf("3: Logarithm (base 2)\n"); + printf("0: Exit Logarithm Menu\n"); + scanf("%d", &logChoice); + return logChoice; +} + +// Choice for Trigonomtri +int getTrigonometricChoice() { + int trigChoice; + printf("Trigonometric functions:\n"); + printf("1: Sine\n"); + printf("2: Cosine\n"); + printf("3: Tangent\n"); + printf("0: Exit Trigonometric Menu\n"); + scanf("%d", &trigChoice); + return trigChoice; +} + + +// Logarithm +void executeLogarithmFunction(double num) { + int logChoice; + + do { + + logChoice = getLogarithmChoice(); + + switch (logChoice) { + case 1: // Logarithm (base 10) + printf("Result: %lf\n", logarithmFunction(num)); + break; + + case 2: // Natural Logarithm (ln) + printf("Result: %lf\n", naturalLogarithmFunction(num)); + break; + + case 3: // Logarithm (base 2) + printf("Result: %lf\n", logarithmBase2Function(num)); + break; + + case 0: // Exit the logarithm menu + break; + + default: + printf("Invalid logarithm function choice. Please try again.\n"); + } + } while (logChoice != 0); +} + +// Trigonometric +void executeTrigonometricFunction(double num) { + int trigChoice; + + do { + + trigChoice = getTrigonometricChoice(); + + switch (trigChoice) { + case 1: // Sine + printf("Result: %lf\n", sineFunction(num)); + break; + + case 2: // Cosine + printf("Result: %lf\n", cosineFunction(num)); + break; + + case 3: // Tangent + printf("Result: %lf\n", tangentFunction(num)); + break; + + case 0: // Exit the trigonometric menu + break; + + default: + printf("Invalid trigonometric function choice. Please try again.\n"); + } + } while (trigChoice != 0); +} + + +void executeScientificFunction(double num, int choice) { + double result; + + switch (choice) { + case 1: // Square root + result = squareRootFunction(num); + printf("Result: %lf\n", result); + break; + + case 2: // Exponential + result = exponentialFunction(num); + printf("Result: %lf\n", result); + break; + + case 3: // Logarithm + executeLogarithmFunction(num); + break; + + case 4: // Trigonometric + executeTrigonometricFunction(num); + break; + + case 0: // Exit the loop + break; + + default: + printf("Invalid choice. Please try again.\n"); + } +} + + +// scientificMode +double scientificMode() { + double result; + int choice; + + do { + double num = getNumberFromUser(); + choice = getScientificModeChoice(); + executeScientificFunction(num, choice); + } while (choice != 0); + + return result; +} diff --git a/src/main/c/testForNumber.c b/src/main/c/testForNumber.c new file mode 100644 index 0000000..511de91 --- /dev/null +++ b/src/main/c/testForNumber.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include + +#include "testForNumber.h" + +double testForNumber() { + double num; + char storage[25]; + char* notANumber; + + do { + //Emptys the standart output buffer to ensure that this function works in loops + //and returns the value of num after every loop + fflush(stdout); + + //fgets() reads the user input into the buffer storage (storage) + //the if condition is true as long as the input isn't empty + if (fgets(storage, sizeof storage, stdin) != NULL) { + //strtod() tries to convert the input into a double + //if there is anything but a number at any point of the array the pointer notANumber will point to this position + num = strtod(storage, ¬ANumber); + } + //isspace makes sure that notANumber doesn't point to an empty space + //the secount part makes sure that notANumber isn't pointing at 0 + } while (!isspace(*notANumber) && *notANumber != 0); + + return num; +} diff --git a/src/main/c/testForNumber.h b/src/main/c/testForNumber.h new file mode 100644 index 0000000..e1d9a91 --- /dev/null +++ b/src/main/c/testForNumber.h @@ -0,0 +1,7 @@ +#ifndef TESTFORNUMBER +#define TESTFORNUMBER + +// get input and check if its a number +double testForNumber(); + +#endif // TESTFORNUMBER \ No newline at end of file diff --git a/src/main/c/testForOperator.c b/src/main/c/testForOperator.c new file mode 100644 index 0000000..4c243e0 --- /dev/null +++ b/src/main/c/testForOperator.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +#include "testForOperator.h" + +char testForOperator() { + //saving the number of operators in a variable so it only needs to be changed in one location + int numberOfOperators = 5; + //array where all valid Operators are saved, can be esily expanded + char oppArray[] = { '+','-','*','/','=' }; + char input; + bool validInput = false; + + //Loops as long as input isn't valid, enters at least one time + while (!validInput) { + scanf("%c\n", &input); + //checks every position of the array if a position is equal to input returns the input, which also stopps the function + for (int i = 0; i <= numberOfOperators; i++) { + if (input == oppArray[i]) { + return input; + } + } + //if the input was deemed invalid it asks for new input and goes to the top of the while loop + printf("The input was not allowed. Please try again!\n"); + } +} diff --git a/src/main/c/testForOperator.h b/src/main/c/testForOperator.h new file mode 100644 index 0000000..34a8467 --- /dev/null +++ b/src/main/c/testForOperator.h @@ -0,0 +1,7 @@ +#ifndef TESTFOROPERATOR +#define TESTFOROPERATOR + +// get input and check if its a operator +char testForOperator(); + +#endif // TESTFOROPERATOR \ No newline at end of file diff --git a/src/test/c/support/.gitkeep b/src/test/c/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/test/c/test_calculator.c b/src/test/c/test_calculator.c index 26b77be..e46172e 100644 --- a/src/test/c/test_calculator.c +++ b/src/test/c/test_calculator.c @@ -1,8 +1,11 @@ -#ifdef TEST #include "unity.h" +#include "BasicMode.h" +#include "main_calculator.h" +#include "testForOperator.h" +#include "testForNumber.h" +#include "programmingMode.h" -#include "calculator.h" void setUp(void) { @@ -25,3 +28,239 @@ void test_addition(void) } #endif // TEST + + double result = add(1, 2); + TEST_ASSERT_EQUAL(3, result); +} + +void test_minus(void) +{ + double result = minus(3, 1); + TEST_ASSERT_EQUAL(2, result); +} + +void test_multiply(void) +{ + double result = multiply(1, 2); + TEST_ASSERT_EQUAL(2, result); +} + +void test_divide(void) +{ + double result = divide(4, 2); + TEST_ASSERT_EQUAL(2, result); + + double result1 = divide(4, 0); + TEST_ASSERT_EQUAL(0, result1); +} + +void test_ConMeter(void) {//5 mm to cm + double result = ConMeter(5, 0, 1); + TEST_ASSERT_EQUAL(0.5, result); +} + +void test_ConMeterToFoot(void) {//5 m to foot + double result = ConMeterToFoot(5, 1, 0); + TEST_ASSERT_EQUAL(16.4042, result); +} +void test_ConKilometerToMiles(void) {//5 miles to km + double result = ConKilometerToMiles(5, 0, 1); + TEST_ASSERT_EQUAL(8.04672, result); +} + +void test_ConGram(void) {//5 mg to g + double result = ConGram(5, 0, 1); + TEST_ASSERT_EQUAL(0.005, result); +} + +void test_ConGramToPounds(void) {//5 kg to pounds + double result = ConGramToPounds(5, 0, 0); + TEST_ASSERT_EQUAL(11.0231, result); +} + +void test_ConTemp(void) {//5 celsius to fahrenheit + double result = ConTemp(5, 0, 1); + TEST_ASSERT_EQUAL(41, result); +} + +void test_ConSpeed(void) {//5 kmh to mph + double result = ConSpeed(5, 0, 1); + TEST_ASSERT_EQUAL(3.10686, result); +} + +void test_ConLiter(void) {//5 l to ml + double result = ConLiter(5, 1, 0); + TEST_ASSERT_EQUAL(5000, result); +} + +void test_ConLiterToGallon(void) {//5 l to gallon + double result = ConLiterToGallon(5, 0, 1); + TEST_ASSERT_EQUAL(1.32086, result); +} + +void test_ConData(void) {//5 b to kb + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.005, result); +} + +void test_ConArea(void) {//5 mm to cm + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.05, result); +} + +void test_ConVolume(void) {//5 mm to cm + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.005, result); +} + +void test_ConClock(void) {//5:00 to 5AM + double result = ConClock(5, 0, 1); + TEST_ASSERT_EQUAL(5, result); +} + +void test_ConTime(void) {//5 ms to s + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.005, result); +} + + +// Square root function +void test_squareRootFunction(void) { + TEST_ASSERT_EQUAL_FLOAT(2.0, squareRootFunction(4.0)); +} + +// Sine function +void test_sineFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(0.0, sineFunction(0.0)); +} + +// Cosine function +void test_cosineFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(1.0, cosineFunction(0.0)); +} + +// Tangent function +void test_tangentFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(0.0, tangentFunction(0.0)); +} + +// Logarithm function +void test_logarithmFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(1.0, logarithmFunction(10.0)); +} + +// Natural logarithm function +void test_naturalLogarithmFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(0.0, naturalLogarithmFunction(1.0)); +} + +// Logarithm with base 2 function +void test_logarithmBase2Function(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(3.0, logarithmBase2Function(8.0)); +} + +// Exponential function +void test_exponentialFunction(void) { + // Your test code here + TEST_ASSERT_EQUAL_FLOAT(1.0, exponentialFunction(0.0)); +} + +// Test case for subtraction +void test_performOperation_Subtraction(void) { + // Arrange + int result; + + // Act + result = performOperation(10, '-', 3); + + // Assert + TEST_ASSERT_EQUAL_INT(7, result); +} + +// Test case for multiplication +void test_performOperation_Multiplication(void) { + // Arrange + int result; + + // Act + result = performOperation(4, '*', 6); + + // Assert + TEST_ASSERT_EQUAL_INT(24, result); +} + +// Test case for division +void test_performOperation_Division(void) { + // Arrange + int result; + + // Act + result = performOperation(8, '/', 2); + + // Assert + TEST_ASSERT_EQUAL_INT(4, result); +} + +// Test case for dividing by zero +void test_performOperation_division_by_zero(void) { + + TEST_ASSERT_EQUAL_INT(0, performOperation(10, '/', 0)); + +} +void test_DecToBin(void) { + // Arrange + long long int result; + + // Act + result = DecToBin(8); + + // Assert + TEST_ASSERT_EQUAL_INT64(100, result); +} +void test_BinToDec(void) { + // Arrange + long long int result; + + // Act + result = BinToDec(100); + + // Assert + TEST_ASSERT_EQUAL_INT64(8, result); +} +void test_additionbin(void) { + // Arrange + long long int result; + + // Act + result = additionbin(1,1); + + // Assert + TEST_ASSERT_EQUAL_INT64(10, result); +} +void test_multiplicationbin(void) { + // Arrange + long long int result; + + // Act + result = multiplicationbin(1,10); + + // Assert + TEST_ASSERT_EQUAL_INT64(10, result); +} +void test_subtractionbin(void) { + // Arrange + long long int result; + + // Act + result = subtractionbin(100,10); + + // Assert + TEST_ASSERT_EQUAL_INT64(10, result); +} + diff --git a/target/test/cache/defines_dependency.yml b/target/test/cache/defines_dependency.yml new file mode 100644 index 0000000..7c38508 --- /dev/null +++ b/target/test/cache/defines_dependency.yml @@ -0,0 +1,9 @@ +--- +src/main/c/main_calculator.c: +- TEST +src/main/c/testForOperator.c: +- TEST +src/main/c/testForNumber.c: +- TEST +src/main/c/programmingMode.c: +- TEST diff --git a/target/test/cache/input.yml b/target/test/cache/input.yml new file mode 100644 index 0000000..5d1078e --- /dev/null +++ b/target/test/cache/input.yml @@ -0,0 +1,243 @@ +--- +:project: + :use_exceptions: false + :use_mocks: true + :compile_threads: 1 + :test_threads: 1 + :use_test_preprocessor: true + :use_preprocessor_directives: false + :use_deep_dependencies: false + :generate_deep_dependencies: true + :auto_link_deep_dependencies: false + :test_file_prefix: test_ + :options_paths: [] + :release_build: false + :use_auxiliary_dependencies: true + :build_root: target + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all +:release_build: + :use_assembly: false + :artifacts: [] +:paths: + :test: + - "+:src/test/c/**" + - "-:src/test/c/support" + :source: + - "+:src/main/c/**" + :support: + - src/test/c/support + :include: [] + :libraries: [] + :test_toolchain_include: [] + :release_toolchain_include: [] +:files: + :test: [] + :source: [] + :assembly: [] + :support: [] + :include: [] +:environment: +- :rake_columns: '120' +:defines: + :test: + - &1 [] + - TEST + :test_preprocess: + - *1 + - TEST + :release: [] + :release_preprocess: [] + :use_test_definition: false + :common: [] +:libraries: + :flag: "-l${1}" + :path_flag: "-L ${1}" + :test: [] + :test_preprocess: [] + :release: [] + :release_preprocess: [] + :placement: :end + :system: + - m +:flags: {} +:extension: + :header: ".h" + :source: ".c" + :assembly: ".s" + :object: ".o" + :libraries: + - ".a" + - ".so" + :executable: ".out" + :map: ".map" + :list: ".lst" + :testpass: ".pass" + :testfail: ".fail" + :dependencies: ".d" +:unity: + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" + :defines: [] +:cmock: + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" + :defines: [] + :includes: [] + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: true + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + :mock_path: target/test/mocks + :verbosity: 3 + :unity_helper: false +:cexception: + :vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor" + :defines: [] +:test_runner: + :includes: [] + :file_suffix: _runner +:tools: + :test_compiler: + :executable: gcc + :name: default_test_compiler + :stderr_redirect: :none + :background_exec: :none + :optional: false + :arguments: + - '' + - '' + - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR + - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE + - "-D$": COLLECTION_DEFINES_TEST_AND_VENDOR + - "-DGNU_COMPILER" + - "-g" + - '' + - -c "${1}" + - -o "${2}" + - "-MMD" + - -MF "${4}" + :test_fixture: + :executable: "${1}" + :name: default_test_fixture + :stderr_redirect: :auto + :background_exec: :none + :optional: false + :arguments: [] + :test_linker: + :executable: gcc + :name: default_test_linker + :stderr_redirect: :none + :background_exec: :none + :optional: false + :arguments: + - '' + - '' + - '' + - '"${1}"' + - "${5}" + - -o "${2}" + - '' + - "${4}" + - '' + :test_file_preprocessor: + :executable: gcc + :name: default_test_file_preprocessor + :stderr_redirect: :none + :background_exec: :none + :optional: false + :arguments: + - '' + - '' + - "-E" + - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR + - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE + - "-D$": COLLECTION_DEFINES_TEST_AND_VENDOR + - "-D$": DEFINES_TEST_PREPROCESS + - "-DGNU_COMPILER" + - '"${1}"' + - -o "${2}" + :test_file_preprocessor_directives: + :executable: gcc + :name: default_test_file_preprocessor_directives + :stderr_redirect: :none + :background_exec: :none + :optional: false + :arguments: + - "-E" + - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR + - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE + - "-D$": COLLECTION_DEFINES_TEST_AND_VENDOR + - "-D$": DEFINES_TEST_PREPROCESS + - "-DGNU_COMPILER" + - "-fdirectives-only" + - '"${1}"' + - -o "${2}" + :test_includes_preprocessor: + :executable: gcc + :name: default_test_includes_preprocessor + :stderr_redirect: :none + :background_exec: :none + :optional: false + :arguments: + - '' + - '' + - "-E" + - "-MM" + - "-MG" + - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR + - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE + - "-D$": COLLECTION_DEFINES_TEST_AND_VENDOR + - "-D$": DEFINES_TEST_PREPROCESS + - "-DGNU_COMPILER" + - '"${1}"' +:test_compiler: + :arguments: [] +:test_linker: + :arguments: [] +:test_fixture: + :arguments: [] + :link_objects: [] +:test_includes_preprocessor: + :arguments: [] +:test_file_preprocessor: + :arguments: [] +:test_file_preprocessor_directives: + :arguments: [] +:test_dependencies_generator: + :arguments: [] +:release_compiler: + :arguments: [] +:release_linker: + :arguments: [] +:release_assembler: + :arguments: [] +:release_dependencies_generator: + :arguments: [] +:plugins: + :load_paths: + - "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins" + :enabled: + - stdout_pretty_tests_report + - module_generator + :display_raw_test_results: false + :stdout_pretty_tests_report_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report" + :module_generator_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/module_generator" +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 +:module_generator: + :project_root: "./" + :source_root: src/ + :test_root: test/ diff --git a/target/test/cache/test_calculator.c b/target/test/cache/test_calculator.c new file mode 100644 index 0000000..3289aba --- /dev/null +++ b/target/test/cache/test_calculator.c @@ -0,0 +1,520 @@ +#include "src/main/c/programmingMode.h" +#include "src/main/c/testForNumber.h" +#include "src/main/c/testForOperator.h" +#include "src/main/c/main_calculator.h" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_addition(void) + +{ + + double result = add(1, 2); + + UnityAssertEqualNumber((UNITY_INT)((3)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(19), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_minus(void) + +{ + + double result = minus(3, 1); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(25), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_multiply(void) + +{ + + double result = multiply(1, 2); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_divide(void) + +{ + + double result = divide(4, 2); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(37), UNITY_DISPLAY_STYLE_INT); + + + + double result1 = divide(4, 0); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result1)), ( + + ((void *)0) + + ), (UNITY_UINT)(40), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConMeter(void) { + + double result = ConMeter(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(45), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConMeterToFoot(void) { + + double result = ConMeterToFoot(5, 1, 0); + + UnityAssertEqualNumber((UNITY_INT)((16.4042)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(50), UNITY_DISPLAY_STYLE_INT); + +} + +void test_ConKilometerToMiles(void) { + + double result = ConKilometerToMiles(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((8.04672)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(54), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConGram(void) { + + double result = ConGram(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(59), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConGramToPounds(void) { + + double result = ConGramToPounds(5, 0, 0); + + UnityAssertEqualNumber((UNITY_INT)((11.0231)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(64), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConTemp(void) { + + double result = ConTemp(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((41)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(69), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConSpeed(void) { + + double result = ConSpeed(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((3.10686)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(74), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConLiter(void) { + + double result = ConLiter(5, 1, 0); + + UnityAssertEqualNumber((UNITY_INT)((5000)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(79), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConLiterToGallon(void) { + + double result = ConLiterToGallon(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((1.32086)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(84), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConData(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(89), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConArea(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.05)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(94), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConVolume(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(99), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConClock(void) { + + double result = ConClock(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(104), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConTime(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(109), UNITY_DISPLAY_STYLE_INT); + +} + + + + + + + +void test_squareRootFunction(void) { + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((2.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((2.0))), (UNITY_FLOAT)((UNITY_FLOAT)((squareRootFunction(4.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(115))); + +} + + + + + +void test_sineFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((sineFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(121))); + +} + + + + + +void test_cosineFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((cosineFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(127))); + +} + + + + + +void test_tangentFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((tangentFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(133))); + +} + + + + + +void test_logarithmFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((logarithmFunction(10.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(139))); + +} + + + + + +void test_naturalLogarithmFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((naturalLogarithmFunction(1.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(145))); + +} + + + + + +void test_logarithmBase2Function(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((3.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((3.0))), (UNITY_FLOAT)((UNITY_FLOAT)((logarithmBase2Function(8.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(151))); + +} + + + + + +void test_exponentialFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((exponentialFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(157))); + +} + + + + + +void test_performOperation_Subtraction(void) { + + + + int result; + + + + + + result = performOperation(10, '-', 3); + + + + + + UnityAssertEqualNumber((UNITY_INT)((7)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(169), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_Multiplication(void) { + + + + int result; + + + + + + result = performOperation(4, '*', 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((24)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(181), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_Division(void) { + + + + int result; + + + + + + result = performOperation(8, '/', 2); + + + + + + UnityAssertEqualNumber((UNITY_INT)((4)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_division_by_zero(void) { + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((performOperation(10, '/', 0))), ( + + ((void *)0) + + ), (UNITY_UINT)(199), UNITY_DISPLAY_STYLE_INT); + + + +} diff --git a/target/test/dependencies/cmock.d b/target/test/dependencies/cmock.d new file mode 100644 index 0000000..6992af8 --- /dev/null +++ b/target/test/dependencies/cmock.d @@ -0,0 +1,6 @@ +target/test/out/c/cmock.o: \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/target/test/dependencies/force_build b/target/test/dependencies/force_build new file mode 100644 index 0000000..e69de29 diff --git a/target/test/dependencies/main_calculator.d b/target/test/dependencies/main_calculator.d new file mode 100644 index 0000000..13621c0 --- /dev/null +++ b/target/test/dependencies/main_calculator.d @@ -0,0 +1,2 @@ +target/test/out/c/main_calculator.o: src/main/c/main_calculator.c \ + src/main/c/main_calculator.h diff --git a/target/test/dependencies/programmingMode.d b/target/test/dependencies/programmingMode.d new file mode 100644 index 0000000..057dedb --- /dev/null +++ b/target/test/dependencies/programmingMode.d @@ -0,0 +1,2 @@ +target/test/out/c/programmingMode.o: src/main/c/programmingMode.c \ + src/main/c/programmingMode.h diff --git a/target/test/dependencies/testForNumber.d b/target/test/dependencies/testForNumber.d new file mode 100644 index 0000000..9ae49d2 --- /dev/null +++ b/target/test/dependencies/testForNumber.d @@ -0,0 +1,2 @@ +target/test/out/c/testForNumber.o: src/main/c/testForNumber.c \ + src/main/c/testForNumber.h diff --git a/target/test/dependencies/testForOperator.d b/target/test/dependencies/testForOperator.d new file mode 100644 index 0000000..e2b19f7 --- /dev/null +++ b/target/test/dependencies/testForOperator.d @@ -0,0 +1,2 @@ +target/test/out/c/testForOperator.o: src/main/c/testForOperator.c \ + src/main/c/testForOperator.h diff --git a/target/test/dependencies/test_calculator.d b/target/test/dependencies/test_calculator.d new file mode 100644 index 0000000..1d59c61 --- /dev/null +++ b/target/test/dependencies/test_calculator.d @@ -0,0 +1,5 @@ +target/test/out/c/test_calculator.o: src/test/c/test_calculator.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/main_calculator.h src/main/c/testForOperator.h \ + src/main/c/testForNumber.h src/main/c/programmingMode.h diff --git a/target/test/dependencies/test_calculator_runner.d b/target/test/dependencies/test_calculator_runner.d new file mode 100644 index 0000000..4972796 --- /dev/null +++ b/target/test/dependencies/test_calculator_runner.d @@ -0,0 +1,4 @@ +target/test/out/c/test_calculator_runner.o: \ + target/test/runners/test_calculator_runner.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/target/test/dependencies/unity.d b/target/test/dependencies/unity.d new file mode 100644 index 0000000..ed190f0 --- /dev/null +++ b/target/test/dependencies/unity.d @@ -0,0 +1,4 @@ +target/test/out/c/unity.o: \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/target/test/out/c/cmock.o b/target/test/out/c/cmock.o new file mode 100644 index 0000000..a04fa7d Binary files /dev/null and b/target/test/out/c/cmock.o differ diff --git a/target/test/out/c/main_calculator.o b/target/test/out/c/main_calculator.o new file mode 100644 index 0000000..2b23025 Binary files /dev/null and b/target/test/out/c/main_calculator.o differ diff --git a/target/test/out/c/programmingMode.o b/target/test/out/c/programmingMode.o new file mode 100644 index 0000000..55810a2 Binary files /dev/null and b/target/test/out/c/programmingMode.o differ diff --git a/target/test/out/c/testForNumber.o b/target/test/out/c/testForNumber.o new file mode 100644 index 0000000..2cbf248 Binary files /dev/null and b/target/test/out/c/testForNumber.o differ diff --git a/target/test/out/c/testForOperator.o b/target/test/out/c/testForOperator.o new file mode 100644 index 0000000..3ae132c Binary files /dev/null and b/target/test/out/c/testForOperator.o differ diff --git a/target/test/out/c/test_calculator.o b/target/test/out/c/test_calculator.o new file mode 100644 index 0000000..1761a8b Binary files /dev/null and b/target/test/out/c/test_calculator.o differ diff --git a/target/test/out/c/test_calculator_runner.o b/target/test/out/c/test_calculator_runner.o new file mode 100644 index 0000000..53d8bb4 Binary files /dev/null and b/target/test/out/c/test_calculator_runner.o differ diff --git a/target/test/out/c/unity.o b/target/test/out/c/unity.o new file mode 100644 index 0000000..d74bb79 Binary files /dev/null and b/target/test/out/c/unity.o differ diff --git a/target/test/out/test_calculator.out b/target/test/out/test_calculator.out new file mode 100755 index 0000000..eb060c8 Binary files /dev/null and b/target/test/out/test_calculator.out differ diff --git a/target/test/preprocess/files/test_calculator.c b/target/test/preprocess/files/test_calculator.c new file mode 100644 index 0000000..3289aba --- /dev/null +++ b/target/test/preprocess/files/test_calculator.c @@ -0,0 +1,520 @@ +#include "src/main/c/programmingMode.h" +#include "src/main/c/testForNumber.h" +#include "src/main/c/testForOperator.h" +#include "src/main/c/main_calculator.h" +#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + +void setUp(void) + +{ + +} + + + +void tearDown(void) + +{ + +} + + + +void test_addition(void) + +{ + + double result = add(1, 2); + + UnityAssertEqualNumber((UNITY_INT)((3)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(19), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_minus(void) + +{ + + double result = minus(3, 1); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(25), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_multiply(void) + +{ + + double result = multiply(1, 2); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_divide(void) + +{ + + double result = divide(4, 2); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(37), UNITY_DISPLAY_STYLE_INT); + + + + double result1 = divide(4, 0); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result1)), ( + + ((void *)0) + + ), (UNITY_UINT)(40), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConMeter(void) { + + double result = ConMeter(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(45), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConMeterToFoot(void) { + + double result = ConMeterToFoot(5, 1, 0); + + UnityAssertEqualNumber((UNITY_INT)((16.4042)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(50), UNITY_DISPLAY_STYLE_INT); + +} + +void test_ConKilometerToMiles(void) { + + double result = ConKilometerToMiles(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((8.04672)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(54), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConGram(void) { + + double result = ConGram(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(59), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConGramToPounds(void) { + + double result = ConGramToPounds(5, 0, 0); + + UnityAssertEqualNumber((UNITY_INT)((11.0231)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(64), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConTemp(void) { + + double result = ConTemp(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((41)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(69), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConSpeed(void) { + + double result = ConSpeed(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((3.10686)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(74), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConLiter(void) { + + double result = ConLiter(5, 1, 0); + + UnityAssertEqualNumber((UNITY_INT)((5000)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(79), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConLiterToGallon(void) { + + double result = ConLiterToGallon(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((1.32086)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(84), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConData(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(89), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConArea(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.05)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(94), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConVolume(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(99), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConClock(void) { + + double result = ConClock(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(104), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_ConTime(void) { + + double result = ConData(5, 0, 1); + + UnityAssertEqualNumber((UNITY_INT)((0.005)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(109), UNITY_DISPLAY_STYLE_INT); + +} + + + + + + + +void test_squareRootFunction(void) { + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((2.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((2.0))), (UNITY_FLOAT)((UNITY_FLOAT)((squareRootFunction(4.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(115))); + +} + + + + + +void test_sineFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((sineFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(121))); + +} + + + + + +void test_cosineFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((cosineFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(127))); + +} + + + + + +void test_tangentFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((tangentFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(133))); + +} + + + + + +void test_logarithmFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((logarithmFunction(10.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(139))); + +} + + + + + +void test_naturalLogarithmFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((0.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((0.0))), (UNITY_FLOAT)((UNITY_FLOAT)((naturalLogarithmFunction(1.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(145))); + +} + + + + + +void test_logarithmBase2Function(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((3.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((3.0))), (UNITY_FLOAT)((UNITY_FLOAT)((logarithmBase2Function(8.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(151))); + +} + + + + + +void test_exponentialFunction(void) { + + + + UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((1.0)) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((1.0))), (UNITY_FLOAT)((UNITY_FLOAT)((exponentialFunction(0.0)))), (( + + ((void *)0) + + )), (UNITY_UINT)((UNITY_UINT)(157))); + +} + + + + + +void test_performOperation_Subtraction(void) { + + + + int result; + + + + + + result = performOperation(10, '-', 3); + + + + + + UnityAssertEqualNumber((UNITY_INT)((7)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(169), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_Multiplication(void) { + + + + int result; + + + + + + result = performOperation(4, '*', 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((24)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(181), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_Division(void) { + + + + int result; + + + + + + result = performOperation(8, '/', 2); + + + + + + UnityAssertEqualNumber((UNITY_INT)((4)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_performOperation_division_by_zero(void) { + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((performOperation(10, '/', 0))), ( + + ((void *)0) + + ), (UNITY_UINT)(199), UNITY_DISPLAY_STYLE_INT); + + + +} diff --git a/target/test/preprocess/includes/test_calculator.c b/target/test/preprocess/includes/test_calculator.c new file mode 100644 index 0000000..56ed68c --- /dev/null +++ b/target/test/preprocess/includes/test_calculator.c @@ -0,0 +1,6 @@ +--- +- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/main_calculator.h +- src/main/c/testForOperator.h +- src/main/c/testForNumber.h +- src/main/c/programmingMode.h diff --git a/target/test/results/test_calculator.pass b/target/test/results/test_calculator.pass new file mode 100644 index 0000000..7b87122 --- /dev/null +++ b/target/test/results/test_calculator.pass @@ -0,0 +1,134 @@ +--- +:source: + :path: src/test/c + :file: test_calculator.c +:successes: +- :test: test_addition + :line: 16 + :message: '' + :unity_test_time: 0 +- :test: test_minus + :line: 22 + :message: '' + :unity_test_time: 0 +- :test: test_multiply + :line: 28 + :message: '' + :unity_test_time: 0 +- :test: test_divide + :line: 34 + :message: '' + :unity_test_time: 0 +- :test: test_ConMeter + :line: 43 + :message: '' + :unity_test_time: 0 +- :test: test_ConMeterToFoot + :line: 48 + :message: '' + :unity_test_time: 0 +- :test: test_ConKilometerToMiles + :line: 52 + :message: '' + :unity_test_time: 0 +- :test: test_ConGram + :line: 57 + :message: '' + :unity_test_time: 0 +- :test: test_ConGramToPounds + :line: 62 + :message: '' + :unity_test_time: 0 +- :test: test_ConTemp + :line: 67 + :message: '' + :unity_test_time: 0 +- :test: test_ConSpeed + :line: 72 + :message: '' + :unity_test_time: 0 +- :test: test_ConLiter + :line: 77 + :message: '' + :unity_test_time: 0 +- :test: test_ConLiterToGallon + :line: 82 + :message: '' + :unity_test_time: 0 +- :test: test_ConData + :line: 87 + :message: '' + :unity_test_time: 0 +- :test: test_ConArea + :line: 92 + :message: '' + :unity_test_time: 0 +- :test: test_ConVolume + :line: 97 + :message: '' + :unity_test_time: 0 +- :test: test_ConClock + :line: 102 + :message: '' + :unity_test_time: 0 +- :test: test_ConTime + :line: 107 + :message: '' + :unity_test_time: 0 +- :test: test_squareRootFunction + :line: 114 + :message: '' + :unity_test_time: 0 +- :test: test_sineFunction + :line: 119 + :message: '' + :unity_test_time: 0 +- :test: test_cosineFunction + :line: 125 + :message: '' + :unity_test_time: 0 +- :test: test_tangentFunction + :line: 131 + :message: '' + :unity_test_time: 0 +- :test: test_logarithmFunction + :line: 137 + :message: '' + :unity_test_time: 0 +- :test: test_naturalLogarithmFunction + :line: 143 + :message: '' + :unity_test_time: 0 +- :test: test_logarithmBase2Function + :line: 149 + :message: '' + :unity_test_time: 0 +- :test: test_exponentialFunction + :line: 155 + :message: '' + :unity_test_time: 0 +- :test: test_performOperation_Subtraction + :line: 161 + :message: '' + :unity_test_time: 0 +- :test: test_performOperation_Multiplication + :line: 173 + :message: '' + :unity_test_time: 0 +- :test: test_performOperation_Division + :line: 185 + :message: '' + :unity_test_time: 0 +- :test: test_performOperation_division_by_zero + :line: 197 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 30 + :passed: 30 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0015222660003928468 diff --git a/target/test/runners/test_calculator_runner.c b/target/test/runners/test_calculator_runner.c new file mode 100644 index 0000000..9459746 --- /dev/null +++ b/target/test/runners/test_calculator_runner.c @@ -0,0 +1,139 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_addition(void); +extern void test_minus(void); +extern void test_multiply(void); +extern void test_divide(void); +extern void test_ConMeter(void); +extern void test_ConMeterToFoot(void); +extern void test_ConKilometerToMiles(void); +extern void test_ConGram(void); +extern void test_ConGramToPounds(void); +extern void test_ConTemp(void); +extern void test_ConSpeed(void); +extern void test_ConLiter(void); +extern void test_ConLiterToGallon(void); +extern void test_ConData(void); +extern void test_ConArea(void); +extern void test_ConVolume(void); +extern void test_ConClock(void); +extern void test_ConTime(void); +extern void test_squareRootFunction(void); +extern void test_sineFunction(void); +extern void test_cosineFunction(void); +extern void test_tangentFunction(void); +extern void test_logarithmFunction(void); +extern void test_naturalLogarithmFunction(void); +extern void test_logarithmBase2Function(void); +extern void test_exponentialFunction(void); +extern void test_performOperation_Subtraction(void); +extern void test_performOperation_Multiplication(void); +extern void test_performOperation_Division(void); +extern void test_performOperation_division_by_zero(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +void verifyTest(void) +{ + CMock_Verify(); +} + +/*=======Test Runner Used To Run Each Test=====*/ +static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num) +{ + Unity.CurrentTestName = name; + Unity.CurrentTestLineNumber = line_num; +#ifdef UNITY_USE_COMMAND_LINE_ARGS + if (!UnityTestMatches()) + return; +#endif + Unity.NumberOfTests++; + UNITY_CLR_DETAILS(); + UNITY_EXEC_TIME_START(); + CMock_Init(); + if (TEST_PROTECT()) + { + setUp(); + func(); + } + if (TEST_PROTECT()) + { + tearDown(); + CMock_Verify(); + } + CMock_Destroy(); + UNITY_EXEC_TIME_STOP(); + UnityConcludeTest(); +} + +/*=======MAIN=====*/ +int main(void) +{ + UnityBegin("test_calculator.c"); + run_test(test_addition, "test_addition", 16); + run_test(test_minus, "test_minus", 22); + run_test(test_multiply, "test_multiply", 28); + run_test(test_divide, "test_divide", 34); + run_test(test_ConMeter, "test_ConMeter", 43); + run_test(test_ConMeterToFoot, "test_ConMeterToFoot", 48); + run_test(test_ConKilometerToMiles, "test_ConKilometerToMiles", 52); + run_test(test_ConGram, "test_ConGram", 57); + run_test(test_ConGramToPounds, "test_ConGramToPounds", 62); + run_test(test_ConTemp, "test_ConTemp", 67); + run_test(test_ConSpeed, "test_ConSpeed", 72); + run_test(test_ConLiter, "test_ConLiter", 77); + run_test(test_ConLiterToGallon, "test_ConLiterToGallon", 82); + run_test(test_ConData, "test_ConData", 87); + run_test(test_ConArea, "test_ConArea", 92); + run_test(test_ConVolume, "test_ConVolume", 97); + run_test(test_ConClock, "test_ConClock", 102); + run_test(test_ConTime, "test_ConTime", 107); + run_test(test_squareRootFunction, "test_squareRootFunction", 114); + run_test(test_sineFunction, "test_sineFunction", 119); + run_test(test_cosineFunction, "test_cosineFunction", 125); + run_test(test_tangentFunction, "test_tangentFunction", 131); + run_test(test_logarithmFunction, "test_logarithmFunction", 137); + run_test(test_naturalLogarithmFunction, "test_naturalLogarithmFunction", 143); + run_test(test_logarithmBase2Function, "test_logarithmBase2Function", 149); + run_test(test_exponentialFunction, "test_exponentialFunction", 155); + run_test(test_performOperation_Subtraction, "test_performOperation_Subtraction", 161); + run_test(test_performOperation_Multiplication, "test_performOperation_Multiplication", 173); + run_test(test_performOperation_Division, "test_performOperation_Division", 185); + run_test(test_performOperation_division_by_zero, "test_performOperation_division_by_zero", 197); + + return UnityEnd(); +} diff --git a/teams.md b/teams.md new file mode 100644 index 0000000..e266a4e --- /dev/null +++ b/teams.md @@ -0,0 +1,6 @@ +- COMMITTER-NAME, FD-NUMMER +- Thomas Papendieck, fdai0127 +- fdai7782 (Jatin Saroay), fdai7782 +- Enrico Schellenberger, fdai7766 +- lukazieg, fdai7814 +- Kabrel, fdai7801