コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: mckayb/school-projects
        public void TestBasicAdd()
        {
            World  w   = new World(1000, 1000, new Dictionary <string, Cube>());
            object obj = new
            {
                loc_x      = 813.0,
                loc_y      = 878.0,
                argb_color = -2987746,
                uid        = 5318,
                food       = false,
                Name       = "Myname",
                Mass       = 1029.1106844616961
            };
            string cubeStr = JsonConvert.SerializeObject(obj);
            Cube   c       = JsonConvert.DeserializeObject <Cube>(cubeStr);

            w.addCube(c);

            Dictionary <string, Cube> cubes = w.GetCubes();

            Assert.AreEqual(cubes.Count, 1);

            w.removeCube(c);
            Dictionary <string, Cube> cubesAgain = w.GetCubes();

            Assert.AreEqual(cubesAgain.Count, 0);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: mckayb/school-projects
        public void testDestroyingExistingCube()
        {
            World w = new World(1000, 1000, new Dictionary <string, Cube>());

            object playerCube = new
            {
                loc_x      = 813.0,
                loc_y      = 878.0,
                argb_color = -2987746,
                uid        = 500,
                food       = false,
                Name       = "Player 1",
                Mass       = 50
            };
            string cubeStr = JsonConvert.SerializeObject(playerCube) + '\n';

            w.updateCubes(cubeStr);


            object playerCubeUpdated = new
            {
                loc_x      = 813.0,
                loc_y      = 878.0,
                argb_color = -2987746,
                uid        = 500,
                food       = false,
                Name       = "Player 1",
                Mass       = 60
            };
            string cubeStrUpdated = JsonConvert.SerializeObject(playerCubeUpdated) + '\n';

            w.updateCubes(cubeStrUpdated);
            Dictionary <String, Cube> cubes = w.GetCubes();
            Cube c = w.getCubeById("500");

            Assert.AreEqual(cubes.Count, 1);
            Assert.AreEqual(c.mass, 60);

            object playerCubeUpdatedAgain = new
            {
                loc_x      = 813.0,
                loc_y      = 878.0,
                argb_color = -2987746,
                uid        = 500,
                food       = false,
                Name       = "Player 1",
                Mass       = 0
            };
            string cubeStrUpdatedAgain = JsonConvert.SerializeObject(playerCubeUpdatedAgain) + '\n';

            w.updateCubes(cubeStrUpdatedAgain);
            Dictionary <String, Cube> cubesAgain = w.GetCubes();
            Cube cu = w.getCubeById("500");

            Assert.AreEqual(cu, null);
            Assert.AreEqual(cubesAgain.Count, 0);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: mckayb/school-projects
        public void TestUpdateCubes()
        {
            World  w       = new World(1000, 1000, new Dictionary <string, Cube>());
            string cubeStr = "";

            for (int i = 0; i < 5; i++)
            {
                object obj = new
                {
                    loc_x      = 813.0,
                    loc_y      = 878.0,
                    argb_color = -2987746,
                    uid        = i,
                    food       = false,
                    Name       = "Myname" + i,
                    Mass       = i * 5
                };

                cubeStr += JsonConvert.SerializeObject(obj) + '\n';
            }
            cubeStr += "{ \"loc_x\": 813.0 ";

            w.updateCubes(cubeStr);

            Dictionary <string, Cube> cubes = w.GetCubes();

            Assert.AreEqual(cubes.Count, 4);
        }