From df2a23a482ce5d685415b61fd723708fdefec0b8 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Fri, 23 Sep 2022 20:58:21 -0400 Subject: Initial commit --- .gitignore | 4 ++ README.md | 25 +++++++++++ testData.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/gen-trig-test.c | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 testData.h create mode 100644 tools/gen-trig-test.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..782cf6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.rej +*.orig +tags diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2f6d57 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# APP2 Programation et algorithmes + +This repo contains work created for the USherbrooke APP2 which introduces +programing as well as basic algorithms. The project requires that we (the +students) create a C library which doesn't rely on third party libraries to do +the following things: + +| Task | filename | Level | +| :------------------------------------ | :---------- | :------- | +| Spot characters in a string | `TODO` | Easy | +| Identify words which are palindromes | `TODO` | Easy | +| Calculate sines (using series) | `TODO` | Medium | +| Calculate cosines (using series) | `TODO` | Medium | +| Matrix addition | `TODO` | Hard* | +| Matrix multiplication | `TODO` | Hard* | + +*This is the first programing APP. The word Hard is used very liberaly here. + +# Structure + +Files which do a specific operation required by the APP are located in their +one files using their aforementioned filenames. Any function used by more than +one of those functions are located in the `format.h` header files. Also, the +`testsuite.c` provides an easy way to test the library with multiple edge cases +using data contained in the `testData.h` header file. diff --git a/testData.h b/testData.h new file mode 100644 index 0000000..fe1c38d --- /dev/null +++ b/testData.h @@ -0,0 +1,113 @@ +/* testData.h + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice + * you can do whatever you want with this stuff. If we meet some day, and you + * think this stuff is worth it, you can buy me a beer in return. + * Benjamin Chausse + * ---------------------------------------------------------------------------- + */ + +// Sample words {{{ +// The following lists contains words of varying length. To test various edge +// cases, some given the following properties: +// - Palindrome +// - Capitalisation (at the beggining) -> mom, erudite +// - Weird capitalisation (mid-word) -> bib, portmanteau +// - Trailing spaces -> sis, heightened, minim +// - Spaces before the words -> sis, unholly, pop +// - Non latin alphabet (greek & russian) +char *word[] = { +"abba", "betrothed", "deified", "elevation", "genesis", "kayak", "murdum", +" pop", "relinquish", "stats", "thirst", "abhorrent", "accentuated", +"agoraphobia", " aibohphobia", "anemia", "bIb", "bittersweet", "bob", +"boredom", "calvary", "civic", "demetrius", "detartrated", "dewed", "dolomite", +"dynasty", "enigmatic", "envy", "erUdite", "eve", "exhaulted", "galadriel", +"genocide", "hannah", "heightened ", "horrendous", "initiation", "level", +"madam", "malayalam", "minim ", "Mom", "mortified", "noon", "nun", "otto", +"peep", "penitentiary", " polymorphism", "poRtmanteau", "quizzaciously", +"racecar", "radar", "redder", "repaper", "rotator", "rotavator", "sagas", +" sis ", "solos", "superlative", "tartigrade", "tattarrattat", "tenacity", +"tenet", " unholly", "wow" "élévation", "μουσικότητα", "неандерталец", +} +// }}} +// Sample numbers {{{ +/* The following list can be used to compare expected sine and cosine outputs + * of the algorithm to pre-calculated values. The expected values were + * generated with the `gen-trig-test.c` using the math.h library. They were + * chosen so that the sample size would contain the following edge cases: + * - Common trigonometric circle identities (0°,30°,45°,60°,90°, etc...) + * - Negative values + * - Values surpassing 2π + */ +int piValues[][] = { +// test-value sin cos + { 0.000000, 0.000000, 1.000000}, // 0° + { 0.523599, 0.500000, 0.866025}, // 30° + { 0.785398, 0.707107, 0.707107}, // 45° + { 1.047198, 0.866025, 0.500000}, // 60° + { 1.570796, 1.000000, -0.000000}, // 90° + { 2.094395, 0.866025, -0.500000}, // 120° + { 2.356194, 0.707107, -0.707107}, // 135° + { 2.617994, 0.500000, -0.866025}, // 150° + { 3.141593, -0.000000, -1.000000}, // 180° + { 3.665191, -0.500000, -0.866025}, // 210° + { 3.926991, -0.707107, -0.707107}, // 225° + { 4.188790, -0.866025, -0.500000}, // 240° + { 4.712389, -1.000000, 0.000000}, // 270° + { 5.235988, -0.866025, 0.500000}, // 300° + { 5.497787, -0.707107, 0.707107}, // 315° + { 5.759586, -0.500000, 0.866025}, // 330° + { 7.853981, 1.000000, 0.000000}, // 450° (over 2pi -> sin=1) + { 9.424778, -0.000000, -1.000000}, // 540° (over 2pi -> cos=1) + {-7.853981, -1.000000, 0.000000}, // -90 negative value -> sin=-1° + {-9.424778, 0.000000, -1.000000} // -180 negative value -> cos=-1° +} +// }}} +// Sample matrices {{{ +/* The following matrices may be used for testing. To test various edge cases + * some were given the following properties: + * - Varying sizes (3x3, 5x3, 3x5) + * - Zero matrix + * - Identity matrix + * + */ +int mtrxA[][] = { + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9} +} + +int mtrxB[][] = { + {3, 1, 4}, + {1, 5, 9}, + {2, 6, 5} +} + +int mtrxNULL[][] = { + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0} +} + +int mtrxID[][] = { + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1} +} + +int mtrxWide[][] = { + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15} +} + +int mtrxTall[][] = { + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + {10, 11, 12}, + {13, 14, 15} +} + +// }}} diff --git a/tools/gen-trig-test.c b/tools/gen-trig-test.c new file mode 100644 index 0000000..365a90d --- /dev/null +++ b/tools/gen-trig-test.c @@ -0,0 +1,72 @@ +/* gen-trig-test.c + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice + * you can do whatever you want with this stuff. If we meet some day, and you + * think this stuff is worth it, you can buy me a beer in return. + * Benjamin Chausse + * ---------------------------------------------------------------------------- + */ +#include +#include +#include + +/* This code was used to generate floating numbers found in testData.h + * It's purpose is to generate a list of expected outputs for the sine + * and cosine function with a given number. It uses the math.h library + * which cannot be used for the assignment and which is therefore a great + * subject to test and compare with. + * + * The generated [][3]int list is organized as follows: + * { original_value, expected_sine, expected_cosine } + * + * Values chosen here test the following edge cases, + * - Common trigonometric circle identities (0°,30°,45°,60°,90°, etc...) + * - Negative values + * - Values surpassing 2π + */ + +int main(){ + + // list of number {{{ + float lst[20] = { + 0, // 0° + M_PI/6, // 30° + M_PI/4, // 45° + M_PI/3, // 60° + M_PI/2, // 90° + 2*M_PI/3, // 120° + 3*M_PI/4, // 135° + 5*M_PI/6, // 150° + M_PI, // 180° + 7*M_PI/6, // 210° + 5*M_PI/4, // 225° + 4*M_PI/3, // 240° + 3*M_PI/2, // 270° + 5*M_PI/3, // 300° + 7*M_PI/4, // 315° + 11*M_PI/6, // 330° + 5*M_PI/2, // 450° (over 2π -> sin=1) + 3*M_PI, // 540° (over 2π -> cos=1) + -5*M_PI/2, // -90 negative value -> sin=-1° + -3*M_PI, // -180 negative value -> cos=-1° + + }; + // }}} + + printf("int piValues[][] = {\n"); + int max = (sizeof(lst)/sizeof(lst[0]))-1; + printf("%d",max); + for (int i=0; i