about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-02-25 18:06:06 +0100
committerEmile <hanemile@protonmail.com>2019-02-25 18:06:06 +0100
commit2607fcb7c3f6a0440bfc0b0ac9d241f57f172e7b (patch)
tree70b4431299959f9fc576fb10aa3e013cb2018ab1
parentbdcbc605fe6a0e91acc27e829c3a7933e9fad786 (diff)
defined tests testing the generation of stars
-rw-r--r--go.mod3
-rw-r--r--go.sum2
-rw-r--r--main_test.go95
3 files changed, 100 insertions, 0 deletions
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)
+			}
+		})
+	}
+}