Package net.sf.arianne.marboard.server.core.engine

Source Code of net.sf.arianne.marboard.server.core.engine.MarboardZoneTest

package net.sf.arianne.marboard.server.core.engine;

import marauroa.common.game.RPObject;
import net.sf.arianne.marboard.server.entity.meta.User;
import net.sf.arianne.marboard.server.entity.shape.Dot;
import net.sf.arianne.marboard.server.entity.shape.Shape;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
* tests for MarboardZone
*
* @author hendrik
*/
public class MarboardZoneTest {

  /**
   * Tests for fixZIndexForShape
   */
  @Test
  public void testFixZIndexForShape() {
    MarboardZone zone = new MarboardZone("testFixZIndexForShape");
    MarboardWorld.get().addRPZone(zone);

    Shape shape = new Dot(0, 0, 0, 0);
    assertFalse(shape.has("z"));

    zone.add(shape);
    assertThat(shape.get("z"), equalTo("1"));

    shape = new Dot(2, 2, 2, 2, 20);
    assertTrue(shape.has("z"));

    zone.add(shape);
    assertThat(shape.get("z"), equalTo("20"));

    shape = new Dot(3, 3, 3, 3);
    assertFalse(shape.has("z"));

    zone.add(shape);
    assertThat(shape.get("z"), equalTo("21"));
   
  }

  /**
   * Test for fixAllZIndicesForAllOtherShapesAbove
   */
  @Test
  public void testFixAllZIndicesForAllOtherShapesAbove() {
    MarboardZone zone = new MarboardZone("testFixAllZIndicesForAllOtherShapesAbove");
    MarboardWorld.get().addRPZone(zone);

    zone.add(new Dot(1, 1, 1, 1, 1));
    zone.add(new Dot(2, 2, 2, 2, 2));
    zone.add(new Dot(4, 4, 4, 4, 3));
    zone.add(new Dot(5, 5, 5, 5, 4));
    zone.add(new Dot(6, 6, 6, 6, 5));

    zone.add(new User("testuser"));
   
    zone.fixAllZIndicesForAllOtherShapesAbove(3, new Dot(3, 3, 3, 3, 3));

    for (RPObject object : zone) {
      assertEquals(object.get("x"), object.get("z"));
    }

    Shape shape = new Dot(7, 7, 7, 7);
    zone.add(shape);
    assertThat(shape.get("z"), equalTo("7"));
  }

  /**
   * protect agains very high z-indices
   */
  @Test
  public void testZIndexOverflow() {
    MarboardZone zone = new MarboardZone("testZIndexOverflow");
    MarboardWorld.get().addRPZone(zone);

    Shape shape = new Dot(1, 1, 1, 1, Integer.MAX_VALUE - 20);
    zone.add(shape);
   
    assertThat(shape.getInt("z"), equalTo(1));
  }
}
TOP

Related Classes of net.sf.arianne.marboard.server.core.engine.MarboardZoneTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.