diff options
Diffstat (limited to 'db_actions_test.go')
-rw-r--r-- | db_actions_test.go | 149 |
1 files changed, 144 insertions, 5 deletions
diff --git a/db_actions_test.go b/db_actions_test.go index 7b96426..b4baec9 100644 --- a/db_actions_test.go +++ b/db_actions_test.go @@ -31,9 +31,10 @@ func TestCalcAllForces(t *testing.T) { db.SetMaxOpenConns(75) type args struct { - database *sql.DB - star structs.Star2D - theta float64 + database *sql.DB + star structs.Star2D + galaxyIndex int64 + theta float64 } tests := []struct { name string @@ -41,7 +42,7 @@ func TestCalcAllForces(t *testing.T) { want structs.Vec2 }{ { - name: "force acting on a single star", + name: "star in the top right quadrant", args: args{ database: db, star: structs.Star2D{ @@ -62,12 +63,150 @@ func TestCalcAllForces(t *testing.T) { Y: 0, }, }, + { + name: "star in the bottom left quadrant", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: -100, + Y: -100, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + theta: 0.5, + }, + want: structs.Vec2{ + X: 0, + Y: 0, + }, + }, + { + name: "star in the far top right quadrant", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: 490, + Y: 490, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + theta: 0.5, + }, + want: structs.Vec2{ + X: 0, + Y: 0, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := CalcAllForces(tt.args.database, tt.args.star, tt.args.theta); !reflect.DeepEqual(got, tt.want) { + if got := CalcAllForces(tt.args.database, tt.args.star, tt.args.galaxyIndex, tt.args.theta); !reflect.DeepEqual(got, tt.want) { t.Errorf("CalcAllForces() = %v, want %v", got, tt.want) } }) } } + +func TestInsertStar(t *testing.T) { + // define a database + db = ConnectToDB() + db.SetMaxOpenConns(75) + + type args struct { + database *sql.DB + star structs.Star2D + index int64 + } + tests := []struct { + name string + args args + }{ + { + name: "Insert a star into the database", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: 100, + Y: 100, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + index: 1, + }, + }, + { + name: "Insert a star into the database", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: 150, + Y: 150, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + index: 1, + }, + }, + { + name: "Insert a star into the database", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: 150, + Y: 150, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + index: 2, + }, + }, + { + name: "Insert a star into the database", + args: args{ + database: db, + star: structs.Star2D{ + C: structs.Vec2{ + X: 100, + Y: 100, + }, + V: structs.Vec2{ + X: 0, + Y: 0, + }, + M: 1000, + }, + index: 2, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + InsertStar(tt.args.database, tt.args.star, tt.args.index) + }) + } +} |