From 362d24ac12ef71242a089ae6f0587b5367b5c882 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 25 Feb 2019 17:48:17 +0100 Subject: Wrote some simple tests for the NFW and PHI functions --- main_test.go | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 main_test.go (limited to 'main_test.go') diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..25061ef --- /dev/null +++ b/main_test.go @@ -0,0 +1,100 @@ +package main + +import ( + "testing" +) + +func Test_rho(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 := rho(tt.args.x, tt.args.y, tt.args.z); got != tt.want { + t.Errorf("rho() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_phi(t *testing.T) { + type args struct { + x float64 + } + tests := []struct { + name string + args args + want float64 + }{ + { + name: "small positive", + args: args{ + x: 0.1, + }, + want: -540602.560824974, + }, + { + name: "small negative", + args: args{ + x: -0.1, + }, + want: -540607.9668716107, + }, + { + name: "zero", + args: args{ + x: 0, + }, + want: -540605.2638297316, + }, + { + name: "large positive", + args: args{ + x: 98754321, + }, + want: -503.515863906017, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := phi(tt.args.x); got != tt.want { + t.Errorf("phi() = %v, want %v", got, tt.want) + } + }) + } +} -- cgit 1.4.1