Sources with test
This commit is contained in:
parent
fd798451f4
commit
9cc368ff2d
4 changed files with 27 additions and 1 deletions
6
src/add.go
Normal file
6
src/add.go
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
// Sophisticated mathematics for sophisticated homosapiens
|
||||||
|
func add(x, y int) int {
|
||||||
|
return x + y
|
||||||
|
}
|
16
src/add_test.go
Normal file
16
src/add_test.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This file is named add_test.go by convention.
|
||||||
|
// The go test command will automatically detect this file and run it.
|
||||||
|
// All test files must be named *_test.go and all test functions must be named Test*.
|
||||||
|
|
||||||
|
// TestAdd is a test function
|
||||||
|
func TestAdd(t *testing.T) {
|
||||||
|
if add(1, 2) != 3 {
|
||||||
|
t.Error("Expected 3")
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Greets the world
|
||||||
func greet() {
|
func greet() {
|
||||||
fmt.Println("Hello World!")
|
fmt.Println("Hello World!")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,5 @@ package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
greet()
|
greet()
|
||||||
|
println(add(1, 2))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue