Skip to content

Commit

Permalink
Test alignment (#16)
Browse files Browse the repository at this point in the history
* update arm. num tests

* reorder beer-song tests
  • Loading branch information
Nenad Misić authored Jun 20, 2024
1 parent 1d48b50 commit 7ed5db8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
fn is_armstrong_number(num: u128) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn is_armstrong_number(num: u32) -> bool {
fn is_armstrong_number(num: u128) -> bool {
panic!("true if {num} is an armstrong number")
}

Expand Down
21 changes: 4 additions & 17 deletions exercises/practice/armstrong-numbers/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,11 @@ fn seven_digit_non_armstrong_number() {
}

#[test]
fn nine_digit_armstrong_number() {
assert!(is_armstrong_number(912_985_153));
fn armstrong_number_containing_seven_zeroes() {
assert!(is_armstrong_number(186_709_961_001_538_790_100_634_132_976_990));
}

#[test]
fn nine_digit_non_armstrong_number() {
assert!(!is_armstrong_number(999_999_999));
}

#[test]
fn ten_digit_non_armstrong_number() {
assert!(!is_armstrong_number(3_999_999_999));
}

// The following number has an Armstrong sum equal to 2^32 plus itself,
// and therefore will be detected as an Armstrong number if you are
// incorrectly using wrapping arithmetic.
#[test]
fn properly_handles_overflow() {
assert!(!is_armstrong_number(4_106_098_957));
fn the_largest_and_last_armstrong_number() {
assert!(is_armstrong_number(115_132_219_018_763_992_565_095_597_973_971_522_401));
}
24 changes: 12 additions & 12 deletions exercises/practice/beer-song/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#[test]
fn verse_with_0_bottles() {
fn first_generic_verse() {
assert_eq!(
beer_song::verse(0),
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
beer_song::verse(99),
"99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n"
);
}

#[test]
fn verse_with_1_bottle() {
fn last_generic_verse() {
assert_eq!(
beer_song::verse(1),
"1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n"
beer_song::verse(3),
"3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n"
);
}

Expand All @@ -23,18 +23,18 @@ fn verse_with_2_bottles() {
}

#[test]
fn first_generic_verse() {
fn verse_with_1_bottle() {
assert_eq!(
beer_song::verse(99),
"99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n"
beer_song::verse(1),
"1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n"
);
}

#[test]
fn last_generic_verse() {
fn verse_with_0_bottles() {
assert_eq!(
beer_song::verse(3),
"3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n"
beer_song::verse(0),
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
);
}

Expand Down

0 comments on commit 7ed5db8

Please sign in to comment.