From 9cc368ff2de9b04dc8cbfba852ac4dee663a9857 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 5 Jan 2024 16:24:45 +0100 Subject: [PATCH] Sources with test --- src/add.go | 6 ++++++ src/add_test.go | 16 ++++++++++++++++ src/greet.go | 5 ++++- src/main.go | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/add.go create mode 100644 src/add_test.go diff --git a/src/add.go b/src/add.go new file mode 100644 index 0000000..d70e9b6 --- /dev/null +++ b/src/add.go @@ -0,0 +1,6 @@ +package main + +// Sophisticated mathematics for sophisticated homosapiens +func add(x, y int) int { + return x + y +} diff --git a/src/add_test.go b/src/add_test.go new file mode 100644 index 0000000..6d71b34 --- /dev/null +++ b/src/add_test.go @@ -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") + } +} diff --git a/src/greet.go b/src/greet.go index 7da9fa1..baabdf1 100644 --- a/src/greet.go +++ b/src/greet.go @@ -1,7 +1,10 @@ package main -import "fmt" +import ( + "fmt" +) +// Greets the world func greet() { fmt.Println("Hello World!") } diff --git a/src/main.go b/src/main.go index 2cebd34..218ca75 100644 --- a/src/main.go +++ b/src/main.go @@ -2,4 +2,5 @@ package main func main() { greet() + println(add(1, 2)) }