From 2607fcb7c3f6a0440bfc0b0ac9d241f57f172e7b Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 25 Feb 2019 18:06:06 +0100 Subject: defined tests testing the generation of stars --- go.mod | 3 ++ go.sum | 2 ++ main_test.go | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main_test.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c8194bf --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module generator + +require github.com/gorilla/mux v1.7.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..62d09fa --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U= +github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..b4dd362 --- /dev/null +++ b/main_test.go @@ -0,0 +1,95 @@ +package main + +import ( + "testing" +) + +func Test_netNFW(t *testing.T) { + type args struct { + x float64 + y float64 + z float64 + } + tests := []struct { + name string + args args + want float64 + }{ + { + name: "small values", + args: args{ + x: 10, + y: 20, + z: 30, + }, + want: 1440.368257365208, + }, + { + name: "negative values", + args: args{ + x: -30, + y: -40, + z: -530, + }, + want: 1043.5804324231447, + }, + { + name: "big values", + args: args{ + x: 10000, + y: 200000, + z: 5, + }, + want: 0.015581605046317826, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := netNFW(tt.args.x, tt.args.y, tt.args.z); got != tt.want { + t.Errorf("netNFW() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_gen(t *testing.T) { + type args struct { + galaxyRange float64 + } + tests := []struct { + name string + args args + want point + }{ + { + name: "Generate a single star (range=1e4)", + args: args{ + galaxyRange: 1e4, + }, + want: point{ + x: 0, + y: 0, + z: 0, + }, + }, + { + name: "Generate a single star (range=1e5)", + args: args{ + galaxyRange: 1e5, + }, + want: point{ + x: 0, + y: 0, + z: 0, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := gen(tt.args.galaxyRange) + if got == (point{}) { + t.Errorf("gen() = %v, want %v", got, tt.want) + } + }) + } +} -- cgit 1.4.1