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

Add exercise 009 #10

Merged
merged 1 commit into from
Mar 18, 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
10 changes: 10 additions & 0 deletions exercises/009-acronym/acronym.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
split($0, words, /[ _-]/)

for (i = 1; i <= length(words); i++) {
letter = substr(words[i], 1, 1)
uppercase_letter = toupper(letter)

printf("%s", uppercase_letter)
}
}
3 changes: 3 additions & 0 deletions exercises/009-acronym/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 009-acronym

- https://exercism.org/tracks/awk/exercises/acronym
74 changes: 74 additions & 0 deletions exercises/009-acronym/tests.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bats

load "../../test/common-setup"
load "../../test/get-test-folder"

TEST_FOLDER=$(get_test_folder $BATS_TEST_FILENAME)
AWK_FILE=$TEST_FOLDER/acronym.awk

setup() {
common_setup
}

@test 'basic' {
run awk -f $AWK_FILE <<< 'Portable Network Graphics'

assert_success
assert_output 'PNG'
}

@test 'lowercase words' {
run awk -f $AWK_FILE <<< 'Ruby on Rails'

assert_success
assert_output 'ROR'
}

@test 'punctuation' {
run awk -f $AWK_FILE <<< 'First In, First Out'

assert_success
assert_output 'FIFO'
}

@test 'all caps word' {
run awk -f $AWK_FILE <<< 'GNU Image Manipulation Program'

assert_success
assert_output 'GIMP'
}

@test 'punctuation without whitespace' {
run awk -f $AWK_FILE <<< 'Complementary metal-oxide semiconductor'

assert_success
assert_output 'CMOS'
}

@test 'very long abbreviation' {
run awk -f $AWK_FILE <<< 'Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me'

assert_success
assert_output 'ROTFLSHTMDCOALM'
}

@test "consecutive delimiters" {
run awk -f $AWK_FILE <<< "Something - I made up from thin air"

assert_success
assert_output "SIMUFTA"
}

@test "apostrophes" {
run awk -f $AWK_FILE <<< "Halley's Comet"

assert_success
assert_output "HC"
}

@test "underscore emphasis" {
run awk -f $AWK_FILE <<< "The Road __Not__ Taken"

assert_success
assert_output "TRNT"
}
Loading