Crossfire JXClient, Trunk  R20561
DoubleMappingTest.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.util;
23 
24 import org.jetbrains.annotations.NotNull;
25 import org.junit.Assert;
26 import org.junit.Test;
27 
32 public class DoubleMappingTest {
33 
38  @Test
39  public void test1() {
40  final DoubleMapping doubleMapping = new DoubleMapping();
41  doubleMapping.insert(0, 0);
42  check(doubleMapping, 0);
43  doubleMapping.insert(1, 0);
44  check(doubleMapping, 1, 0);
45  doubleMapping.insert(1, 1);
46  check(doubleMapping, 2, 1, 0);
47  doubleMapping.insert(3, 2);
48  check(doubleMapping, 3, 1, 0, 2);
49  doubleMapping.insert(1, 2);
50  check(doubleMapping, 4, 2, 1, 0, 3);
51  doubleMapping.remove(0);
52  check(doubleMapping, 2, 1, 0, 3);
53  doubleMapping.remove(1);
54  check(doubleMapping, 1, 0, 2);
55  }
56 
63  private static void check(@NotNull final DoubleMapping doubleMapping, @NotNull final int... values) {
64  for (int i = 0; i < values.length; i++) {
65  final int dst = doubleMapping.getDst(i);
66  Assert.assertEquals("index "+i, values[i], dst);
67  Assert.assertEquals("index "+i, i, doubleMapping.getSrc(dst));
68  }
69  }
70 
71 }
static void check(@NotNull final DoubleMapping doubleMapping, @NotNull final int... values)
Checks that a DoubleMapping instance contains the expected values.
void insert(final int src, final int dst)
Adds a mapping.
void test1()
Checks that basic operations for on DoubleMapping instances do work.
Regression tests for class DoubleMapping.
Maintains a bidirectional mapping from a set of integers to the same range of integers.
void remove(final int src)
Removes a mapping.