diff options
author | Emile <hanemile@protonmail.com> | 2019-02-25 17:48:17 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-02-25 17:48:17 +0100 |
commit | 362d24ac12ef71242a089ae6f0587b5367b5c882 (patch) | |
tree | fbbcae4e63406c301e0a4cf5e78910a8f8591a76 | |
parent | 1cc6abe2d27314193f4619f7a81577d64ede3e71 (diff) |
Wrote some simple tests for the NFW and PHI functions
-rw-r--r-- | main_test.go | 100 |
1 files changed, 100 insertions, 0 deletions
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) + } + }) + } +} |