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

triangle: return int, fixes #164 #202

Merged
merged 3 commits into from
Feb 16, 2024
Merged
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
6 changes: 6 additions & 0 deletions exercises/practice/triangle/.meta/example.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ triangle_equality:

global is_equilateral:
is_equilateral:
xor eax, eax
xor edx, edx
push QWORD [rsp+24]
push QWORD [rsp+24]
push QWORD [rsp+24]
Expand All @@ -45,6 +47,9 @@ is_equilateral:
ret
global is_isosceles:
is_isosceles:
xor eax, eax
xor ecx, ecx
xor edx, edx
movsd xmm5, QWORD [rsp+8]
movsd xmm6, QWORD [rsp+16]
movsd xmm4, QWORD [rsp+24]
Expand Down Expand Up @@ -72,6 +77,7 @@ is_isosceles:

global is_scalene
is_scalene:
xor eax, eax
push QWORD [rsp+24]
push QWORD [rsp+24]
push QWORD [rsp+24]
Expand Down
45 changes: 22 additions & 23 deletions exercises/practice/triangle/triangle_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Version: 0

#include <stdbool.h>
#include "vendor/unity.h"

typedef struct {
Expand All @@ -9,9 +8,9 @@ typedef struct {
double c;
} triangle_t;

extern bool is_equilateral(triangle_t sides);
extern bool is_isosceles(triangle_t sides);
extern bool is_scalene(triangle_t sides);
extern int is_equilateral(triangle_t sides);
extern int is_isosceles(triangle_t sides);
extern int is_scalene(triangle_t sides);

void setUp(void) {
}
Expand All @@ -21,115 +20,115 @@ void tearDown(void) {

void test_equilateral_triangle_all_sides_are_equal(void) {
triangle_t sides = { 2, 2, 2 } ;
TEST_ASSERT_TRUE(is_equilateral(sides));
TEST_ASSERT_EQUAL_INT(1, is_equilateral(sides));
}

void test_equilateral_triangle_any_side_is_unequal(void) {
TEST_IGNORE();
triangle_t sides = { 2, 3, 2 } ;
TEST_ASSERT_FALSE(is_equilateral(sides));
TEST_ASSERT_EQUAL_INT(0, is_equilateral(sides));
}

void test_equilateral_triangle_no_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 5, 4, 6 } ;
TEST_ASSERT_FALSE(is_equilateral(sides));
TEST_ASSERT_EQUAL_INT(0, is_equilateral(sides));
}

void test_equilateral_triangle_all_zero_sides_is_not_a_triangle(void) {
TEST_IGNORE();
triangle_t sides = { 0, 0, 0 } ;
TEST_ASSERT_FALSE(is_equilateral(sides));
TEST_ASSERT_EQUAL_INT(0, is_equilateral(sides));
}

void test_equilateral_triangle_sides_may_be_floats(void) {
TEST_IGNORE();
triangle_t sides = { 0.5, 0.5, 0.5 } ;
TEST_ASSERT_TRUE(is_equilateral(sides));
TEST_ASSERT_EQUAL_INT(1, is_equilateral(sides));
}

void test_isosceles_triangle_last_two_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 3, 4, 4 } ;
TEST_ASSERT_TRUE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(1, is_isosceles(sides));
}

void test_isosceles_triangle_first_two_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 4, 4, 3 } ;
TEST_ASSERT_TRUE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(1, is_isosceles(sides));
}

void test_isosceles_triangle_first_and_last_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 4, 3, 4 } ;
TEST_ASSERT_TRUE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(1, is_isosceles(sides));
}

void test_isosceles_triangle_equilateral_triangles_are_also_isosceles(void) {
TEST_IGNORE();
triangle_t sides = { 4, 4, 4 } ;
TEST_ASSERT_TRUE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(1, is_isosceles(sides));
}

void test_isosceles_triangle_no_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 2, 3, 4 } ;
TEST_ASSERT_FALSE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(0, is_isosceles(sides));
}

void test_isosceles_triangle_first_triangle_inequality_violation(void) {
TEST_IGNORE();
triangle_t sides = { 1, 1, 3 } ;
TEST_ASSERT_FALSE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(0, is_isosceles(sides));
}

void test_isosceles_triangle_second_triangle_inequality_violation(void) {
TEST_IGNORE();
triangle_t sides = { 1, 3, 1 } ;
TEST_ASSERT_FALSE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(0, is_isosceles(sides));
}

void test_isosceles_triangle_third_triangle_inequality_violation(void) {
TEST_IGNORE();
triangle_t sides = { 3, 1, 1 } ;
TEST_ASSERT_FALSE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(0, is_isosceles(sides));
}

void test_isosceles_triangle_sides_may_be_floats(void) {
TEST_IGNORE();
triangle_t sides = { 0.5, 0.4, 0.5 } ;
TEST_ASSERT_TRUE(is_isosceles(sides));
TEST_ASSERT_EQUAL_INT(1, is_isosceles(sides));
}

void test_scalene_triangle_no_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 5, 4, 6 } ;
TEST_ASSERT_TRUE(is_scalene(sides));
TEST_ASSERT_EQUAL_INT(1, is_scalene(sides));
}

void test_scalene_triangle_all_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 4, 4, 4 } ;
TEST_ASSERT_FALSE(is_scalene(sides));
TEST_ASSERT_EQUAL_INT(0, is_scalene(sides));
}

void test_scalene_triangle_two_sides_are_equal(void) {
TEST_IGNORE();
triangle_t sides = { 4, 4, 3 } ;
TEST_ASSERT_FALSE(is_scalene(sides));
TEST_ASSERT_EQUAL_INT(0, is_scalene(sides));
}

void test_scalene_triangle_may_not_violate_triangle_inequality(void) {
TEST_IGNORE();
triangle_t sides = { 7, 3, 2 } ;
TEST_ASSERT_FALSE(is_scalene(sides));
TEST_ASSERT_EQUAL_INT(0, is_scalene(sides));
}

void test_scalene_triangle_sides_may_be_floats(void) {
TEST_IGNORE();
triangle_t sides = { 0.5, 0.4, 0.6 } ;
TEST_ASSERT_TRUE(is_scalene(sides));
TEST_ASSERT_EQUAL_INT(1, is_scalene(sides));
}

int main(void) {
Expand Down