Skip to content

Commit

Permalink
collatz error INVALID_NUMBER (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode authored Oct 20, 2024
1 parent fee92ee commit 3bb14ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion exercises/practice/collatz-conjecture/.meta/example.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.equ INVALID_NUMBER, -1

.text
.globl steps

Expand Down Expand Up @@ -26,7 +28,7 @@ steps:
b .loop

.invalid:
mov x0, #-1
mov x0, INVALID_NUMBER

.return:
ret
2 changes: 2 additions & 0 deletions exercises/practice/collatz-conjecture/collatz_conjecture.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.equ INVALID_NUMBER, -1

.text
.globl steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdint.h>

#define ERROR_VALUE -1
#define INVALID_NUMBER -1

extern int steps(int64_t number);

Expand Down Expand Up @@ -33,12 +33,12 @@ void test_large_number_of_even_and_odd_steps(void) {

void test_zero_is_an_error(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(-1, steps(0));
TEST_ASSERT_EQUAL_INT(INVALID_NUMBER, steps(0));
}

void test_negative_value_is_an_error(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(-1, steps(-15));
TEST_ASSERT_EQUAL_INT(INVALID_NUMBER, steps(-15));
}

void test_large_positive(void) {
Expand All @@ -48,7 +48,7 @@ void test_large_positive(void) {

void test_large_negative(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(-1, steps(-7001002003));
TEST_ASSERT_EQUAL_INT(INVALID_NUMBER, steps(-7001002003));
}

int main(void) {
Expand Down
4 changes: 2 additions & 2 deletions generators/exercises/collatz_conjecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>
#define ERROR_VALUE -1
#define INVALID_NUMBER -1
extern int steps(int64_t number);
"""
Expand Down Expand Up @@ -33,5 +33,5 @@ def extra_cases():
def gen_func_body(prop, inp, expected):
number = inp["number"]
if expected.__class__ == dict:
expected = -1
expected = 'INVALID_NUMBER'
return f"TEST_ASSERT_EQUAL_INT({expected}, {prop}({number}));\n"

0 comments on commit 3bb14ee

Please sign in to comment.