Skip to content

Commit

Permalink
Sync bash from problem specs (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacG authored Nov 12, 2023
1 parent 205e8da commit b3eb8c4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 46 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/hello-world/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
".meta/example.sh"
]
},
"blurb": "The classical introductory exercise. Just say \"Hello, World!\".",
"blurb": "Exercism's classic introductory exercise. Just say \"Hello, World!\".",
"source": "This is an exercise to introduce users to using Exercism",
"source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
}
6 changes: 4 additions & 2 deletions exercises/practice/phone-number/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ The first three digits of the local number represent the _exchange code_, follow
The format is usually represented as

```text
(NXX)-NXX-XXXX
NXX NXX-XXXX
```

where `N` is any digit from 2 through 9 and `X` is any digit from 0 through 9.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present.
Sometimes they also have the country code (represented as `1` or `+1`) prefixed.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code if present.

For example, the inputs

Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/poker/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ description = "a tie has multiple winners"
[61ed83a9-cfaa-40a5-942a-51f52f0a8725]
description = "multiple hands with the same high cards, tie compares next highest ranked, down to last card"

[da01becd-f5b0-4342-b7f3-1318191d0580]
description = "winning high card hand also has the lowest card"

[f7175a89-34ff-44de-b3d7-f6fd97d1fca4]
description = "one pair beats high card"

[e114fd41-a301-4111-a9e7-5a7f72a76561]
description = "highest pair wins"

[b3acd3a7-f9fa-4647-85ab-e0a9e07d1365]
description = "both hands have the same pair, high card wins"

[935bb4dc-a622-4400-97fa-86e7d06b1f76]
description = "two pairs beats one pair"

Expand Down Expand Up @@ -54,6 +60,10 @@ description = "both hands have three of a kind, tie goes to highest ranked tripl
[eb856cc2-481c-4b0d-9835-4d75d07a5d9d]
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"

[26a4a7d4-34a2-4f18-90b4-4a8dd35d2bb1]
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"
reimplements = "eb856cc2-481c-4b0d-9835-4d75d07a5d9d"

[a858c5d9-2f28-48e7-9980-b7fa04060a60]
description = "a straight beats three of a kind"

Expand All @@ -78,6 +88,10 @@ description = "flush beats a straight"
[4d90261d-251c-49bd-a468-896bf10133de]
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"

[e04137c5-c19a-4dfc-97a1-9dfe9baaa2ff]
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"
reimplements = "4d90261d-251c-49bd-a468-896bf10133de"

[3a19361d-8974-455c-82e5-f7152f5dba7c]
description = "full house beats a flush"

Expand Down
100 changes: 58 additions & 42 deletions exercises/practice/poker/poker.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ load bats-extra

@test "single hand always wins" {
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5S 7H 8D JC"
run bash poker.sh "4S 5S 7H 8D JC"
assert_success
assert_line "4S 5S 7H 8D JC"
assert_equal "${#lines[@]}" "1"
}

@test "highest card out of all hands wins" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4D 5S 6S 8D 3C" "2S 4C 7S 9H 10H" "3S 4S 5D 6H JH"
run bash poker.sh "4D 5S 6S 8D 3C" "2S 4C 7S 9H 10H" "3S 4S 5D 6H JH"
assert_success
assert_line "3S 4S 5D 6H JH"
assert_equal "${#lines[@]}" "1"
}

@test "a tie has multiple winners" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4D 5S 6S 8D 3C" "2S 4C 7S 9H 10H" "3S 4S 5D 6H JH" "3H 4H 5C 6C JD"
run bash poker.sh "4D 5S 6S 8D 3C" "2S 4C 7S 9H 10H" "3S 4S 5D 6H JH" "3H 4H 5C 6C JD"
assert_success
assert_line "3S 4S 5D 6H JH"
assert_line "3H 4H 5C 6C JD"
Expand All @@ -31,55 +31,87 @@ load bats-extra

@test "multiple hands with the same high cards, tie compares next highest ranked, down to last card" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "3S 5H 6S 8D 7H" "2S 5D 6D 8C 7S"
run bash poker.sh "3S 5H 6S 8D 7H" "2S 5D 6D 8C 7S"
assert_success
assert_line "3S 5H 6S 8D 7H"
assert_equal "${#lines[@]}" "1"
}

@test "winning high card hand also has the lowest card" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 5H 6S 8D 7H" "3S 4D 6D 8C 7S"
assert_success
assert_line "2S 5H 6S 8D 7H"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have the same pair, high card wins" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4H 4S AH JC 3D" "4C 4D AS 5D 6C"
assert_success
assert_line "4H 4S AH JC 3D"
assert_equal "${#lines[@]}" "1"
}

@test "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S AH AS 7C AD" "4S AH AS 8C AD"
assert_success
assert_line "4S AH AS 8C AD"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have a flush, tie goes to high card, down to the last one if necessary" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4H 7H 8H 9H 6H" "2S 4S 5S 6S 7S"
assert_success
assert_line "4H 7H 8H 9H 6H"
assert_equal "${#lines[@]}" "1"
}

@test "one pair beats high card" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 6C 8D KH" "2S 4H 6S 4D JH"
run bash poker.sh "4S 5H 6C 8D KH" "2S 4H 6S 4D JH"
assert_success
assert_line "2S 4H 6S 4D JH"
assert_equal "${#lines[@]}" "1"
}

@test "highest pair wins" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 2H 6S 2D JH" "2S 4H 6C 4D JD"
run bash poker.sh "4S 2H 6S 2D JH" "2S 4H 6C 4D JD"
assert_success
assert_line "2S 4H 6C 4D JD"
assert_equal "${#lines[@]}" "1"
}

@test "two pairs beats one pair" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 8H 6S 8D JH" "4S 5H 4C 8C 5C"
run bash poker.sh "2S 8H 6S 8D JH" "4S 5H 4C 8C 5C"
assert_success
assert_line "4S 5H 4C 8C 5C"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have two pairs, highest ranked pair wins" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 8H 2D 8D 3H" "4S 5H 4C 8S 5D"
run bash poker.sh "2S 8H 2D 8D 3H" "4S 5H 4C 8S 5D"
assert_success
assert_line "2S 8H 2D 8D 3H"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have two pairs, with the same highest ranked pair, tie goes to low pair" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S QS 2C QD JH" "JD QH JS 8D QC"
run bash poker.sh "2S QS 2C QD JH" "JD QH JS 8D QC"
assert_success
assert_line "JD QH JS 8D QC"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have two identically ranked pairs, tie goes to remaining card (kicker)" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "JD QH JS 8D QC" "JS QS JC 2D QD"
run bash poker.sh "JD QH JS 8D QC" "JS QS JC 2D QD"
assert_success
assert_line "JD QH JS 8D QC"
assert_equal "${#lines[@]}" "1"
Expand All @@ -103,47 +135,39 @@ load bats-extra

@test "three of a kind beats two pair" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 8H 2H 8D JH" "4S 5H 4C 8S 4H"
run bash poker.sh "2S 8H 2H 8D JH" "4S 5H 4C 8S 4H"
assert_success
assert_line "4S 5H 4C 8S 4H"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have three of a kind, tie goes to highest ranked triplet" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 2H 2C 8D JH" "4S AH AS 8C AD"
assert_success
assert_line "4S AH AS 8C AD"
assert_equal "${#lines[@]}" "1"
}

@test "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S AH AS 7C AD" "4S AH AS 8C AD"
run bash poker.sh "2S 2H 2C 8D JH" "4S AH AS 8C AD"
assert_success
assert_line "4S AH AS 8C AD"
assert_equal "${#lines[@]}" "1"
}

@test "a straight beats three of a kind" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 4C 8D 4H" "3S 4D 2S 6D 5C"
run bash poker.sh "4S 5H 4C 8D 4H" "3S 4D 2S 6D 5C"
assert_success
assert_line "3S 4D 2S 6D 5C"
assert_equal "${#lines[@]}" "1"
}

@test "aces can end a straight (10 J Q K A)" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 4C 8D 4H" "10D JH QS KD AC"
run bash poker.sh "4S 5H 4C 8D 4H" "10D JH QS KD AC"
assert_success
assert_line "10D JH QS KD AC"
assert_equal "${#lines[@]}" "1"
}

@test "aces can start a straight (A 2 3 4 5)" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 4C 8D 4H" "4D AH 3S 2D 5C"
run bash poker.sh "4S 5H 4C 8D 4H" "4D AH 3S 2D 5C"
assert_success
assert_line "4D AH 3S 2D 5C"
assert_equal "${#lines[@]}" "1"
Expand All @@ -160,87 +184,79 @@ load bats-extra

@test "both hands with a straight, tie goes to highest ranked card" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 6C 7S 8D 5H" "5S 7H 8S 9D 6H"
run bash poker.sh "4S 6C 7S 8D 5H" "5S 7H 8S 9D 6H"
assert_success
assert_line "5S 7H 8S 9D 6H"
assert_equal "${#lines[@]}" "1"
}

@test "even though an ace is usually high, a 5-high straight is the lowest-scoring straight" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2H 3C 4D 5D 6H" "4S AH 3S 2D 5H"
run bash poker.sh "2H 3C 4D 5D 6H" "4S AH 3S 2D 5H"
assert_success
assert_line "2H 3C 4D 5D 6H"
assert_equal "${#lines[@]}" "1"
}

@test "flush beats a straight" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4C 6H 7D 8D 5H" "2S 4S 5S 6S 7S"
run bash poker.sh "4C 6H 7D 8D 5H" "2S 4S 5S 6S 7S"
assert_success
assert_line "2S 4S 5S 6S 7S"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have a flush, tie goes to high card, down to the last one if necessary" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4H 7H 8H 9H 6H" "2S 4S 5S 6S 7S"
assert_success
assert_line "4H 7H 8H 9H 6H"
assert_equal "${#lines[@]}" "1"
}

@test "full house beats a flush" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "3H 6H 7H 8H 5H" "4S 5H 4C 5D 4H"
run bash poker.sh "3H 6H 7H 8H 5H" "4S 5H 4C 5D 4H"
assert_success
assert_line "4S 5H 4C 5D 4H"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have a full house, tie goes to highest-ranked triplet" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4H 4S 4D 9S 9D" "5H 5S 5D 8S 8D"
run bash poker.sh "4H 4S 4D 9S 9D" "5H 5S 5D 8S 8D"
assert_success
assert_line "5H 5S 5D 8S 8D"
assert_equal "${#lines[@]}" "1"
}

@test "with multiple decks, both hands have a full house with the same triplet, tie goes to the pair" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "5H 5S 5D 9S 9D" "5H 5S 5D 8S 8D"
run bash poker.sh "5H 5S 5D 9S 9D" "5H 5S 5D 8S 8D"
assert_success
assert_line "5H 5S 5D 9S 9D"
assert_equal "${#lines[@]}" "1"
}

@test "four of a kind beats a full house" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 4D 5D 4H" "3S 3H 2S 3D 3C"
run bash poker.sh "4S 5H 4D 5D 4H" "3S 3H 2S 3D 3C"
assert_success
assert_line "3S 3H 2S 3D 3C"
assert_equal "${#lines[@]}" "1"
}

@test "both hands have four of a kind, tie goes to high quad" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "2S 2H 2C 8D 2D" "4S 5H 5S 5D 5C"
run bash poker.sh "2S 2H 2C 8D 2D" "4S 5H 5S 5D 5C"
assert_success
assert_line "4S 5H 5S 5D 5C"
assert_equal "${#lines[@]}" "1"
}

@test "with multiple decks, both hands with identical four of a kind, tie determined by kicker" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "3S 3H 2S 3D 3C" "3S 3H 4S 3D 3C"
run bash poker.sh "3S 3H 2S 3D 3C" "3S 3H 4S 3D 3C"
assert_success
assert_line "3S 3H 4S 3D 3C"
assert_equal "${#lines[@]}" "1"
}

@test "straight flush beats four of a kind" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4S 5H 5S 5D 5C" "7S 8S 9S 6S 10S"
run bash poker.sh "4S 5H 5S 5D 5C" "7S 8S 9S 6S 10S"
assert_success
assert_line "7S 8S 9S 6S 10S"
assert_equal "${#lines[@]}" "1"
Expand Down Expand Up @@ -272,7 +288,7 @@ load bats-extra

@test "both hands have straight flush, tie goes to highest-ranked card" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash poker.sh "4H 6H 7H 8H 5H" "5S 7S 8S 9S 6S"
run bash poker.sh "4H 6H 7H 8H 5H" "5S 7S 8S 9S 6S"
assert_success
assert_line "5S 7S 8S 9S 6S"
assert_equal "${#lines[@]}" "1"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/pop-count/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
".meta/example.sh"
]
},
"blurb": "Help Eluid count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.",
"blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.",
"source": "Christian Willner, Eric Willigers",
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
}

0 comments on commit b3eb8c4

Please sign in to comment.