moving from gitlab
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "math.h"
|
||||
|
||||
int add(int x, int y) { return x + y; }
|
||||
int subtract(int x, int y) { return x - y; }
|
||||
double divide(int x, int y) {
|
||||
if (y == 0)
|
||||
return 0.0;
|
||||
return (double)x / y;
|
||||
}
|
||||
int mulitply(int x, int y) { return x * y; }
|
||||
int doubleVal(int x) { return x * 2; }
|
||||
int power(int x, int p) {
|
||||
int val = 1;
|
||||
for (int i = 1; i <= p; i++) {
|
||||
val *= x;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
double squareRoot(int x) {
|
||||
double sqrt, val;
|
||||
|
||||
sqrt = divide(x, 2);
|
||||
val = 0;
|
||||
|
||||
while (sqrt != val) {
|
||||
val = sqrt;
|
||||
|
||||
sqrt = (x / val + val) / 2;
|
||||
}
|
||||
return sqrt;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
int add(int x, int y);
|
||||
int subtract(int x, int y);
|
||||
double divide(int x, int y);
|
||||
int mulitply(int x, int y);
|
||||
int doubleVal(int x);
|
||||
int power(int x, int p);
|
||||
double squareRoot(int x);
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "math.h"
|
||||
#include <criterion/alloc.h>
|
||||
#include <criterion/criterion.h>
|
||||
#include <criterion/internal/new_asserts.h>
|
||||
#include <criterion/new/assert.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Test(basic, test1) { cr_assert(1 == 1); }
|
||||
|
||||
Test(basic, test2) { cr_expect(2 == 2); }
|
||||
|
||||
void setup() { printf("setup!\n"); }
|
||||
|
||||
void teardown() { printf("teardown\n"); }
|
||||
|
||||
Test(basic, setup_teardown, .init = setup, .fini = teardown) {
|
||||
cr_assert(true);
|
||||
}
|
||||
|
||||
Test(basic, signal, .signal = SIGSEGV) {
|
||||
|
||||
int arr[2] = {1, 2};
|
||||
arr[2] = 3;
|
||||
}
|
||||
|
||||
Test(basic, noSignal) {
|
||||
|
||||
int arr[2] = {1, 2};
|
||||
arr[2] = 3;
|
||||
}
|
||||
|
||||
Test(basic, fail) { cr_fail("this test will always fail until.."); }
|
||||
|
||||
Test(basic, pass) { cr_skip("feature is not implemented"); }
|
||||
|
||||
struct thing {
|
||||
int *param;
|
||||
};
|
||||
|
||||
Test(basic, memory) {
|
||||
struct thing thing1 = {.param = cr_malloc(sizeof(int))};
|
||||
|
||||
// run tests...
|
||||
cr_free(thing1.param);
|
||||
}
|
||||
|
||||
Test(math, add) { cr_assert(add(1, 1) == 2); }
|
||||
Test(math, sub) { cr_assert(subtract(5, 10) == -5); }
|
||||
Test(math, mulitpy) { cr_assert(mulitply(2, 3) == 6); }
|
||||
Test(math, sqrt25) { cr_assert(squareRoot(25) == 5.0); }
|
||||
Test(math, sqrt2) {
|
||||
double res = squareRoot(2);
|
||||
printf("sqrt2 == %.5f\n", res);
|
||||
cr_assert(epsilon_eq(flt, res, 1.4142135, 0.00001));
|
||||
}
|
||||
Reference in New Issue
Block a user