コード例 #1
0
ファイル: GPSTest.java プロジェクト: SimonRichards/robosim
  /** Test of getOutput method, of class GPS with noise. */
  @Test
  public void testNoisyOutput() {
    System.out.println("getOutput with noise");

    // Set up test data
    GPS instance = new GPS(0.2);
    XPoint location = new XPoint(10, 20);
    SensorTestingRobot robot = new SensorTestingRobot(0, location, 0);

    instance.setObject(robot);

    // Check the values are correct
    assertEquals(10, instance.getOutput().getX(), 10 * 0.2);
    assertEquals(20, instance.getOutput().getY(), 20 * 0.2);
  }
コード例 #2
0
  @Test
  public void testUpdateLocation() {
    // Wings wings = new Wings();
    Engine[] engine = new Engine[2];
    GPS gps = new GPS();
    final double MAXRPM = 10000;

    engine[0] = new Engine(MAXRPM);
    engine[1] = new Engine(MAXRPM);
    engine[0].turnOn();
    engine[1].turnOn();
    engine[0].setCurrentRPM(2000);
    engine[1].setCurrentRPM(2000);
    System.out.println(gps.getLat());
    System.out.println(gps.getLon());

    gps.updateLocation(45, 100, 0.1);
    assertEquals(1.964185503, gps.getLat(), .001);
    assertEquals(1.964185503, gps.getLon(), .001);

    gps.updateLocation(180, 300, 0.1);
    assertEquals(1.964185503, gps.getLat(), .001);
    assertEquals(-478.0 / 75, gps.getLon(), .01);

    try {
      gps.updateLocation(180, -300, 0.01);
      fail();
    } catch (IllegalArgumentException e) {
      // Exception Caught, Pass Negative Speed Test
    }

    try {
      gps.updateLocation(-180, 300, 0.01);
      fail();
    } catch (IllegalArgumentException e) {
      // Exception Caught, Pass Negative Speed Test
    }

    try {
      gps.updateLocation(180, 300, -0.01);
      fail();
    } catch (IllegalArgumentException e) {
      // Exception Caught, Pass Negative Speed Test
    }
  }
コード例 #3
0
  @Test
  public void testUpdateAltitude() {
    Engine[] engine = new Engine[2];
    GPS gps = new GPS();
    final double MAXRPM = 10000;
    engine[0].turnOn();
    engine[1].turnOn();
    engine[0] = new Engine(MAXRPM);
    engine[1] = new Engine(MAXRPM);

    gps.updateAltitude(20, 200, 100, 0.1);
    assertEquals(gps.getAltitude(), 0.0, 0.1);

    gps.updateAltitude(20, 200, 200, 0.1);
    assertEquals(gps.getAltitude(), 1.90011, 0.1);

    gps.updateAltitude(40, 400, 200, 0.1);
    assertEquals(gps.getAltitude(), 9.042196, 0.1);

    gps.updateAltitude(-30, 200, 100, 0.1);
    assertEquals(gps.getAltitude(), 6.264418, 0.1);

    try {
      gps.updateAltitude(-110, 400, 200, 0.1);
      fail();
    } catch (IllegalArgumentException e) {
      // Passed, caught the correct error
    }

    try {
      gps.updateAltitude(110, -400, 200, 0.1);
      fail();
    } catch (IllegalArgumentException e) {
      // Passed, caught the correct error
    }

    try {
      gps.updateAltitude(110, 400, 200, -0.1);
      fail();
    } catch (IllegalArgumentException e) {
      // Passed, caught the correct error
    }
  }