Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void TestGetCubeById()
        {
            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);

            Cube cubeFromWorld = w.getCubeById(c.uid);

            Assert.AreEqual(c, cubeFromWorld);
        }
Exemplo n.º 3
0
        public void testGetCubeByIdNull()
        {
            World w = new World(1000, 1000, new Dictionary <string, Cube>());

            Assert.AreEqual(null, w.getCubeById("200"));
        }