Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling updates #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

language: c

script: make dep && make && make test

comiler:
-gcc
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ geometry_test.o: geometry_test.c geometry.h
geometry.o: geometry.c geometry.h
$(CC) $(CFLAGS) $< -o $@

test: geometry_test
./geometry_test
dep:
sudo apt-get update
sudo apt-get install check

clean:
Expand Down
5 changes: 5 additions & 0 deletions geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ void coord_2d_midpoint(coord_2d_t* mid, const coord_2d_t* a, const coord_2d_t* b
mid->y = ((a->y + b->y) / 2.0 );

}

double coord_2d_area_triangle(const coord_2d_t* a, const coord_2d_t* b, const coord_2d_t* c){
double area = ((a->x*(b->y - c->y)) + (b->x*(c->y - a->y)) + (c->x*(a->y - b->y)))/2;
return area;
}
2 changes: 2 additions & 0 deletions geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ bool coord_2d_eq(const coord_2d_t* a, const coord_2d_t* b);

/* Calculate the midpoint between two 2D coordinates and load into mid */
void coord_2d_midpoint(coord_2d_t* mid, const coord_2d_t* a, const coord_2d_t* b);

double coord_2d_area_triangle(const coord_2d_t* a, const coord_2d_t* b, const coord_2d_t* c);
33 changes: 32 additions & 1 deletion geometry_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ START_TEST(test_2d_midpoint)
}
END_TEST

START_TEST(test_2d_area_triangle)
{
coord_2d_t a;
coord_2d_t b;
coord_2d_t c;

a.x = 0.00;
a.y = 0.00;
b.x = 2.00;
b.y = 0.00;
c.x = 2.00;
c.y = 2.00;

ck_assert(coord_2d_area_triangle(&a, &b, &c) == 2.00);

a.x = 0.00;
a.y = 0.00;
b.x = 10.00;
b.y = 0.00;
c.x = 10.00;
c.y = 10.00;

ck_assert(coord_2d_area_triangle(&a, &b, &c) == 50.00);



}
END_TEST
/* coord_2d Test Suite */
Suite* coord_2d_suite(void)
{
Expand All @@ -162,11 +190,14 @@ Suite* coord_2d_suite(void)
TCase* tc_2d_midpoint = tcase_create("coord_2d_midpoint");
tcase_add_test(tc_2d_midpoint, test_2d_midpoint);

TCase* tc_2d_area_triangle = tcase_create("coord_2d_area_triangle");
tcase_add_test(tc_2d_area_triangle, test_2d_area_triangle);

/* Add Cases to Suite */
suite_add_tcase(s, tc_2d_eq);
suite_add_tcase(s, tc_2d_dist);
suite_add_tcase(s, tc_2d_midpoint);

suite_add_tcase(s, tc_2d_area_triangle);
/* Return Suite */
return s;

Expand Down