func TestConnectionProcessor(t *testing.T) { Convey("Connection Processor", t, func() { physics := processor.DefaultPhysics() physics.TurnCommandModifier = 1.0 physics.AccelerationCommandModifier = 1.0 conn_processor := processor.ConnectCommandProcessor{Physics: &physics} c := cmd.NewConnect("abc123") c2 := cmd.NewConnect("abc") c.UserId = "abc123" c2.UserId = "abc" connect := cmd.GameCommand(&c) connect2 := cmd.GameCommand(&c2) game_state := physics.NewGameState() So(len(game_state.Vehicles), ShouldEqual, 0) conn_processor.Run(&game_state, connect) So(len(game_state.Vehicles), ShouldEqual, 1) conn_processor.Run(&game_state, connect) So(len(game_state.Vehicles), ShouldEqual, 1) conn_processor.Run(&game_state, connect2) So(len(game_state.Vehicles), ShouldEqual, 2) }) }
func TestFireProcessor(t *testing.T) { Convey("Fire Processor", t, func() { physics := processor.DefaultPhysics() physics.TurnCommandModifier = 1.0 physics.AccelerationCommandModifier = 1.0 fireProcessor := processor.FireCommandProcessor{Physics: &physics} connectProcessor := processor.ConnectCommandProcessor{Physics: &physics} fireCommand := cmd.NewFire() fireCommand.UserId = "abc" connectCommand := cmd.NewConnect("abc") connectCommand.UserId = "abc" fire := cmd.GameCommand(&fireCommand) connect := cmd.GameCommand(&connectCommand) game_state := physics.NewGameState() So(len(game_state.Bullets), ShouldEqual, 0) So(len(game_state.Vehicles), ShouldEqual, 0) connectProcessor.Run(&game_state, connect) So(len(game_state.Vehicles), ShouldEqual, 1) fireProcessor.Run(&game_state, fire) So(len(game_state.Bullets), ShouldEqual, 1) badFireCommand := cmd.NewFire() badFireCommand.UserId = "nobody" badFire := cmd.GameCommand(&badFireCommand) fireProcessor.Run(&game_state, badFire) So(len(game_state.Bullets), ShouldEqual, 1) }) }