Skip to content

Commit

Permalink
tidy (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode authored Nov 25, 2024
1 parent d948f8e commit f1ad5e5
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 45 deletions.
8 changes: 4 additions & 4 deletions exercises/practice/atbash-cipher/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ decode:

process:
mov x3, x2 /* remaining letters in group */
mov w6, 32 /* space */
mov w7, #122 /* 'z' */
mov w6, #' '
mov w7, #'z'

.read:
ldrb w4, [x1], #1 /* load byte, post-increment */
cbz w4, .end

sub w5, w4, #48 /* '0' */
sub w5, w4, #'0'
cmp w5, #10
blo .accept /* unsigned < */

orr w5, w4, #32 /* force lower case */
sub w5, w5, 97 /* 'a' */
sub w5, w5, #'a'
cmp w5, #26
bhs .read /* unsigned >= */

Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/bob/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ response:
ldrb w1, [x0], #1 /* load byte, with post-increment */
cbz x1, .select_response

cmp x1, #32 /* space */
cmp x1, #' '
ble .read

mov x2, x1 /* non-whitespace character */
sub x1, x1, #65
sub x1, x1, #'A'
cmp x1, #26 /* upper case? */
cinc x3, x3, lo /* increment on unsigned < */

Expand All @@ -42,7 +42,7 @@ response:
add x3, x3, :lo12:calm
adrp x4, whoa
add x4, x4, :lo12:whoa
cmp x2, #63 /* question mark */
cmp x2, #'?'
csel x0, x3, x4, eq
ret

Expand All @@ -51,7 +51,7 @@ response:
add x3, x3, :lo12:sure
adrp x4, whatever
add x4, x4, :lo12:whatever
cmp x2, #63 /* question mark */
cmp x2, #'?'
csel x0, x3, x4, eq
ret

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/isbn-verifier/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ is_valid:
beq .loop

sub x1, x1, #1 /* decrement number of digits remaining */
sub x3, x2, #48 /* '0' */
sub x3, x2, #'0'
cmp x3, #10
bhs .non_digit /* unsigned >= */

Expand All @@ -28,7 +28,7 @@ is_valid:
cbnz x1, .reject

mov x3, #10
cmp x2, #88 /* 'X' */
cmp x2, #'X'
beq .add

.reject:
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/isogram/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ is_isogram:
cbz x3, .accept

orr x3, x3, #32 /* force lower-case */
sub x3, x3, #97
sub x3, x3, #'a'
cmp x3, #26
bhs .loop /* unsigned >= */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,82 @@ void tearDown(void) {
}

void test_finds_the_largest_product_if_span_equals_length(void) {
TEST_ASSERT_EQUAL_INT(18, largest_product(2, "29"));
TEST_ASSERT_EQUAL_INT64(18, largest_product(2, "29"));
}

void test_can_find_the_largest_product_of_2_with_numbers_in_order(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(72, largest_product(2, "0123456789"));
TEST_ASSERT_EQUAL_INT64(72, largest_product(2, "0123456789"));
}

void test_can_find_the_largest_product_of_2(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(48, largest_product(2, "576802143"));
TEST_ASSERT_EQUAL_INT64(48, largest_product(2, "576802143"));
}

void test_can_find_the_largest_product_of_3_with_numbers_in_order(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(504, largest_product(3, "0123456789"));
TEST_ASSERT_EQUAL_INT64(504, largest_product(3, "0123456789"));
}

void test_can_find_the_largest_product_of_3(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(270, largest_product(3, "1027839564"));
TEST_ASSERT_EQUAL_INT64(270, largest_product(3, "1027839564"));
}

void test_can_find_the_largest_product_of_5_with_numbers_in_order(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(15120, largest_product(5, "0123456789"));
TEST_ASSERT_EQUAL_INT64(15120, largest_product(5, "0123456789"));
}

void test_can_get_the_largest_product_of_a_big_number(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(23520, largest_product(6, "73167176531330624919225119674426574742355349194934"));
TEST_ASSERT_EQUAL_INT64(23520, largest_product(6, "73167176531330624919225119674426574742355349194934"));
}

void test_reports_zero_if_the_only_digits_are_zero(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(0, largest_product(2, "0000"));
TEST_ASSERT_EQUAL_INT64(0, largest_product(2, "0000"));
}

void test_reports_zero_if_all_spans_include_zero(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(0, largest_product(3, "99099"));
TEST_ASSERT_EQUAL_INT64(0, largest_product(3, "99099"));
}

void test_rejects_span_longer_than_string_length(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(INSUFFICIENT_DIGITS, largest_product(4, "123"));
TEST_ASSERT_EQUAL_INT64(INSUFFICIENT_DIGITS, largest_product(4, "123"));
}

void test_reports_1_for_empty_string_and_empty_product_0_span(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(1, largest_product(0, ""));
TEST_ASSERT_EQUAL_INT64(1, largest_product(0, ""));
}

void test_reports_1_for_nonempty_string_and_empty_product_0_span(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(1, largest_product(0, "123"));
TEST_ASSERT_EQUAL_INT64(1, largest_product(0, "123"));
}

void test_rejects_empty_string_and_nonzero_span(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(INSUFFICIENT_DIGITS, largest_product(1, ""));
TEST_ASSERT_EQUAL_INT64(INSUFFICIENT_DIGITS, largest_product(1, ""));
}

void test_rejects_invalid_character_in_digits(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(INVALID_CHARACTER, largest_product(2, "1234a5"));
TEST_ASSERT_EQUAL_INT64(INVALID_CHARACTER, largest_product(2, "1234a5"));
}

void test_rejects_negative_span(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(NEGATIVE_SPAN, largest_product(-1, "12345"));
TEST_ASSERT_EQUAL_INT64(NEGATIVE_SPAN, largest_product(-1, "12345"));
}

void test_large_span(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT(131681894400, largest_product(17, "98765432123456789"));
TEST_ASSERT_EQUAL_INT64(131681894400, largest_product(17, "98765432123456789"));
}

int main(void) {
Expand Down
10 changes: 5 additions & 5 deletions exercises/practice/nucleotide-count/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ nucleotide_counts:
ldrb w2, [x1], #1 /* load byte, post-increment */
cbz w2, .report

cmp w2, 'A'
cmp w2, #'A'
beq .adenine

cmp w2, 'C'
cmp w2, #'C'
beq .cytosine

cmp w2, 'G'
cmp w2, #'G'
beq .guanine

cmp w2, 'T'
cmp w2, #'T'
beq .thymine

mov w2, -1
mov w2, #-1
strh w2, [x0], #2
strh w2, [x0], #2
strh w2, [x0], #2
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/pangram/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ is_pangram:
cbz x3, .return

orr x3, x3, #32 /* force lower-case */
sub x3, x3, #97
sub x3, x3, #'a'
cmp x3, #26
bhs .loop /* unsigned >= */

Expand Down
12 changes: 6 additions & 6 deletions exercises/practice/pig-latin/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ vowels:
# | -------- | ------------ | ------- | --------------------------------------- |
# | `x0` | input/output | address | output pointer |
# | `x1` | input | address | beginning of word(s) |
# | `x3` | temporary | byte | previous letter in word |
# | `x4` | temporary | byte | current letter in word |
# | `x5` | temporary | byte | second letter in word |
# | `x6` | temporary | byte | non-zero when current letter is a vowel |
# | `x7` | temporary | byte | 'a' |
# | `x8` | temporary | byte | 'y' |
# | `w3` | temporary | byte | previous letter in word |
# | `w4` | temporary | byte | current letter in word |
# | `w5` | temporary | byte | second letter in word |
# | `w6` | temporary | byte | non-zero when current letter is a vowel |
# | `w7` | temporary | byte | 'a' |
# | `w8` | temporary | byte | 'y' |
# | `x9` | temporary | address | vowels table, minus 'a' |
# | `x10` | temporary | address | position in current word |
# | `x11` | temporary | address | end of current word |
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ convert:
mov x5, x1
udiv x1, x5, x3 /* divide value by 10 */
msub x6, x1, x3, x5 /* remainder, i.e. output digit */
add w6, w6, #48 /* '0' */
add w6, w6, #'0'
strb w6, [x2], #1 /* store, post-increment */
cbnz x1, .write /* loop until value is 0 */

Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/rotational-cipher/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ rotate:
ldrb w4, [x1], #1 /* load byte, post-increment */
and w7, w4, #32 /* 32 if lower case, 0 if upper case */
sub w5, w4, w7 /* force upper case */
sub w5, w5, 65 /* subtract 'A' to obtain index in alphabet */
sub w5, w5, #'A' /* index in alphabet */
cmp w5, #26
bhs .write /* unsigned >= */

add w5, w5, 65 /* 'A' */
add w5, w5, #'A'
add w5, w5, w2 /* shift */
sub w6, w5, #26
cmp w5, #90 /* 'Z' */
cmp w5, #'Z'
csel w5, w5, w6, le /* w5 if <= 'Z', otherwise w5 - 26 */

orr w4, w5, w7 /* rotated letter, with original case */
Expand Down
8 changes: 7 additions & 1 deletion exercises/practice/square-root/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
/* extern uint64_t square_root(uint64_t radicand); */
square_root:
mov x1, x0 /* radicand */
mov x0, #1 /* initial guess */

clz x0, x1 /* count leading zero bits */
mov x2, #64
sub x0, x2, x0 /* number of bits, excluding leading zero bits */
lsr x0, x0, #1 /* number of bits, halved */
mov x2, #1
lsl x0, x2, x0 /* initial guess */

.loop:
mov x2, x0 /* current guess */
Expand Down
2 changes: 1 addition & 1 deletion generators/exercises/largest_series_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def gen_func_body(prop, inp, expected):
expectations["span must be smaller than string length"] = "INSUFFICIENT_DIGITS"
expected = expectations[expected["error"]]

return f"TEST_ASSERT_EQUAL_INT({expected}, largest_product({span}, \"{digits}\"));\n"
return f"TEST_ASSERT_EQUAL_INT64({expected}, largest_product({span}, \"{digits}\"));\n"

0 comments on commit f1ad5e5

Please sign in to comment.