exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

hello_world_test.go (1311B)


      1 package greeting
      2 
      3 import "testing"
      4 
      5 // Define a function named HelloWorld that takes no arguments,
      6 // and returns a string.
      7 // In other words, define a function with the following signature:
      8 // HelloWorld() string
      9 
     10 func TestHelloWorld(t *testing.T) {
     11 	expected := "Hello, World!"
     12 	if observed := HelloWorld(); observed != expected {
     13 		t.Fatalf("HelloWorld() = %v, want %v", observed, expected)
     14 	}
     15 }
     16 
     17 // BenchmarkHelloWorld() is a benchmarking function. These functions follow the
     18 // form `func BenchmarkXxx(*testing.B)` and can be used to test the performance
     19 // of your implementation. They may not be present in every exercise, but when
     20 // they are you can run them by including the `-bench` flag with the `go test`
     21 // command, like so: `go test -v --bench . --benchmem`
     22 //
     23 // You will see output similar to the following:
     24 //
     25 // BenchmarkHelloWorld   	2000000000	         0.46 ns/op
     26 //
     27 // This means that the loop ran 2000000000 times at a speed of 0.46 ns per loop.
     28 //
     29 // While benchmarking can be useful to compare different iterations of the same
     30 // exercise, keep in mind that others will run the same benchmarks on different
     31 // machines, with different specs, so the results from these benchmark tests may
     32 // vary.
     33 func BenchmarkHelloWorld(b *testing.B) {
     34 	for i := 0; i < b.N; i++ {
     35 		HelloWorld()
     36 	}
     37 }