diff --git a/about_concurrency.go b/about_concurrency.go new file mode 100644 index 0000000..e455a34 --- /dev/null +++ b/about_concurrency.go @@ -0,0 +1,31 @@ +package go_koans + +func isPrimeNumber(possiblePrime int) bool { + for underPrime := 2; underPrime < possiblePrime; underPrime++ { + if possiblePrime % underPrime == 0 { + return false + } + } + return true +} + +func findPrimeNumbers(channel chan int) { + for i := 2; /* infinite loop */ ; i++ { + // your code goes here + + assert(i < 100) // i is afraid of heights + } +} + +func aboutConcurrency() { + ch := make(chan int) + + assert(__delete_me__) // concurrency can be almost trivial + // your code goes here + + assert(<-ch == 2) + assert(<-ch == 3) + assert(<-ch == 5) + assert(<-ch == 7) + assert(<-ch == 11) +} diff --git a/about_panics.go b/about_panics.go new file mode 100644 index 0000000..eef33ed --- /dev/null +++ b/about_panics.go @@ -0,0 +1,5 @@ +package go_koans + +func aboutPanics() { + panic("crap") +} diff --git a/setup_koans_test.go b/setup_koans_test.go index 6b2e132..4931c68 100644 --- a/setup_koans_test.go +++ b/setup_koans_test.go @@ -15,6 +15,7 @@ var __int__ int = -1 var __byte__ byte = 255 var __bool__ bool = false // ugh var __float32__ float32 = -1.0 +var __delete_me__ bool = false func TestKoans(t *testing.T) { aboutNumbers() @@ -31,10 +32,7 @@ func TestKoans(t *testing.T) { aboutPointers() aboutStructs() aboutAllocation() - - // TODO: ie, gameplan - //aboutGoroutines() - //aboutChannels() + aboutConcurrency() //aboutPanics() fmt.Printf("\n%c[32;1mYou won life. Good job.\n\n", 27)