Last active
April 9, 2025 14:56
-
-
Save drio/031e54d5893e542c0ae2894cc815f903 to your computer and use it in GitHub Desktop.
R center appl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func cracklePop(n int) string { | |
if n%3 == 0 && n%5 == 0 { | |
return "CracklePop" | |
} else if n%3 == 0 { | |
return "Crackle" | |
} else if n%5 == 0 { | |
return "Pop" | |
} | |
return fmt.Sprintf("%d", n) | |
} | |
func main() { | |
if len(os.Args) > 1 && os.Args[1] == "--test" { | |
runTests() | |
return | |
} | |
for i := 1; i <= 100; i++ { | |
fmt.Println(cracklePop(i)) | |
} | |
} | |
// I am doing this because I wanted to keep the tests within the same file | |
func runTests() { | |
tests := []struct { | |
input int | |
want string | |
}{ | |
{1, "1"}, | |
{3, "Crackle"}, | |
{5, "Pop"}, | |
{15, "CracklePop"}, | |
{30, "CracklePop"}, | |
{33, "Crackle"}, | |
{50, "Pop"}, | |
{100, "Pop"}, | |
} | |
passed := 0 | |
for _, tt := range tests { | |
got := cracklePop(tt.input) | |
if got != tt.want { | |
fmt.Printf("FAIL: cracklePop(%d) = %q; want %q\n", tt.input, got, tt.want) | |
} else { | |
passed++ | |
} | |
} | |
fmt.Printf("%d/%d tests passed\n", passed, len(tests)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment