aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/utils/AngleUtilsTest.java
blob: 7ab39090ae9cc2cc665f67d2d26d7b303f6191db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cgeo.geocaching.utils;

import static org.assertj.core.api.Assertions.assertThat;

import android.test.AndroidTestCase;

public class AngleUtilsTest extends AndroidTestCase {

    public static void testNormalize() {
        assertThat(AngleUtils.normalize(0)).isEqualTo(0.0f);
        assertThat(AngleUtils.normalize(360)).isEqualTo(0.0f);
        assertThat(AngleUtils.normalize(720)).isEqualTo(0.0f);
        assertThat(AngleUtils.normalize(-360)).isEqualTo(0.0f);
        assertThat(AngleUtils.normalize(-720)).isEqualTo(0.0f);
        assertThat(AngleUtils.normalize(721)).isEqualTo(1.0f);
        assertThat(AngleUtils.normalize(-721)).isEqualTo(359.0f);
    }

    public static void testDifference() {
        assertEquals(0.0f, AngleUtils.difference(12, 12));
        assertEquals(0.0f, AngleUtils.difference(372, 12));
        assertEquals(0.0f, AngleUtils.difference(12, 372));
        assertEquals(10.0f, AngleUtils.difference(10, 20));
        assertEquals(10.0f, AngleUtils.difference(355, 5));
        assertEquals(10.0f, AngleUtils.difference(715, -715));
        assertEquals(-10.0f, AngleUtils.difference(20, 10));
        assertEquals(-10.0f, AngleUtils.difference(5, 355));
        assertEquals(-10.0f, AngleUtils.difference(-715, 715));
        assertEquals(-180.0f, AngleUtils.difference(-90, 90));
        assertEquals(-180.0f, AngleUtils.difference(90, -90));
    }
}