dos2unix
This commit is contained in:
parent
c35ba96302
commit
34197dc3da
206
09/gradlew.bat
vendored
206
09/gradlew.bat
vendored
@ -1,103 +1,103 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
@ -1,81 +1,81 @@
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
|
||||
/**
|
||||
* @author flurin gishamer
|
||||
* holds information about a single competitor from
|
||||
* the zurich marathon
|
||||
*/
|
||||
public class Competitor implements Comparable<Competitor> {
|
||||
private String name;
|
||||
private String country;
|
||||
private long time;
|
||||
private int jg;
|
||||
private int startNr;
|
||||
private int rank;
|
||||
|
||||
public Competitor(int startNr, String name, int jg, String country, String time) throws Exception {
|
||||
this.name = name;
|
||||
this.country = country;
|
||||
this.jg = jg;
|
||||
this.startNr = startNr;
|
||||
this.time = parseTime(time);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getJg() {
|
||||
return jg;
|
||||
}
|
||||
|
||||
public void setRank(int rank) {
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
private static long parseTime(String s) throws ParseException {
|
||||
DateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
|
||||
Date date = sdf.parse(s);
|
||||
return date.getTime();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss.S");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" Start Nr: ");
|
||||
sb.append(startNr);
|
||||
sb.append(" ");
|
||||
sb.append(name);
|
||||
sb.append(" ");
|
||||
sb.append(Integer.toString(jg));
|
||||
sb.append(" ");
|
||||
sb.append(country);
|
||||
sb.append(" ");
|
||||
sb.append(df.format(new Date(time)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Competitor toCompare) {
|
||||
int c = name.compareTo(toCompare.name);
|
||||
c = (c != 0)?c:jg - toCompare.jg;
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
hash = hash * 13 + name.hashCode();
|
||||
hash = hash * 17 + jg;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
return (compareTo((Competitor)obj) == 0);
|
||||
}
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
|
||||
/**
|
||||
* @author flurin gishamer
|
||||
* holds information about a single competitor from
|
||||
* the zurich marathon
|
||||
*/
|
||||
public class Competitor implements Comparable<Competitor> {
|
||||
private String name;
|
||||
private String country;
|
||||
private long time;
|
||||
private int jg;
|
||||
private int startNr;
|
||||
private int rank;
|
||||
|
||||
public Competitor(int startNr, String name, int jg, String country, String time) throws Exception {
|
||||
this.name = name;
|
||||
this.country = country;
|
||||
this.jg = jg;
|
||||
this.startNr = startNr;
|
||||
this.time = parseTime(time);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getJg() {
|
||||
return jg;
|
||||
}
|
||||
|
||||
public void setRank(int rank) {
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
private static long parseTime(String s) throws ParseException {
|
||||
DateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
|
||||
Date date = sdf.parse(s);
|
||||
return date.getTime();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss.S");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" Start Nr: ");
|
||||
sb.append(startNr);
|
||||
sb.append(" ");
|
||||
sb.append(name);
|
||||
sb.append(" ");
|
||||
sb.append(Integer.toString(jg));
|
||||
sb.append(" ");
|
||||
sb.append(country);
|
||||
sb.append(" ");
|
||||
sb.append(df.format(new Date(time)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Competitor toCompare) {
|
||||
int c = name.compareTo(toCompare.name);
|
||||
c = (c != 0)?c:jg - toCompare.jg;
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
hash = hash * 13 + name.hashCode();
|
||||
hash = hash * 17 + jg;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
return (compareTo((Competitor)obj) == 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,88 +1,88 @@
|
||||
import java.util.*;
|
||||
|
||||
public class MyHashtable<K,V> implements java.util.Map<K,V> {
|
||||
private K[] keys = (K[]) new Object[10];
|
||||
private V[] values = (V[]) new Object[10];
|
||||
|
||||
private int hash(Object k) {
|
||||
int h = Math.abs(k.hashCode());
|
||||
return h % keys.length;
|
||||
}
|
||||
|
||||
public MyHashtable(int size) {
|
||||
// to be done
|
||||
}
|
||||
|
||||
// Removes all mappings from this map (optional operation).
|
||||
public void clear() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Associates the specified value with the specified key in this map (optional operation).
|
||||
public V put(K key, V value) {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns the value to which this map maps the specified key.
|
||||
public V get(Object key) {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns true if this map contains no key-value mappings.
|
||||
public boolean isEmpty() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Removes the mapping for this key from this map if present (optional operation).
|
||||
public V remove(Object key) {
|
||||
// to be done (Aufgabe 3)
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns the number of key-value mappings in this map.
|
||||
public int size() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// Returns a set view of the keys contained in this map.
|
||||
public Set keySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Copies all of the mappings from the specified map to this map (optional operation).
|
||||
public void putAll(Map t) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns a collection view of the values contained in this map.
|
||||
public Collection values() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns true if this map contains a mapping for the specified key.
|
||||
public boolean containsKey(Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns true if this map maps one or more keys to the specified value.
|
||||
public boolean containsValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns a set view of the mappings contained in this map.
|
||||
public Set entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Compares the specified object with this map for equality.
|
||||
public boolean equals(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns the hash code value for this map.
|
||||
public int hashCode() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MyHashtable<K,V> implements java.util.Map<K,V> {
|
||||
private K[] keys = (K[]) new Object[10];
|
||||
private V[] values = (V[]) new Object[10];
|
||||
|
||||
private int hash(Object k) {
|
||||
int h = Math.abs(k.hashCode());
|
||||
return h % keys.length;
|
||||
}
|
||||
|
||||
public MyHashtable(int size) {
|
||||
// to be done
|
||||
}
|
||||
|
||||
// Removes all mappings from this map (optional operation).
|
||||
public void clear() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Associates the specified value with the specified key in this map (optional operation).
|
||||
public V put(K key, V value) {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns the value to which this map maps the specified key.
|
||||
public V get(Object key) {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns true if this map contains no key-value mappings.
|
||||
public boolean isEmpty() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Removes the mapping for this key from this map if present (optional operation).
|
||||
public V remove(Object key) {
|
||||
// to be done (Aufgabe 3)
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns the number of key-value mappings in this map.
|
||||
public int size() {
|
||||
// to be done
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// Returns a set view of the keys contained in this map.
|
||||
public Set keySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Copies all of the mappings from the specified map to this map (optional operation).
|
||||
public void putAll(Map t) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// Returns a collection view of the values contained in this map.
|
||||
public Collection values() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns true if this map contains a mapping for the specified key.
|
||||
public boolean containsKey(Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns true if this map maps one or more keys to the specified value.
|
||||
public boolean containsValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns a set view of the mappings contained in this map.
|
||||
public Set entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Compares the specified object with this map for equality.
|
||||
public boolean equals(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// Returns the hash code value for this map.
|
||||
public int hashCode() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,179 +1,179 @@
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.*;
|
||||
|
||||
class Town {
|
||||
int hashCode;
|
||||
String name;
|
||||
String nb;
|
||||
Town (int hashCode, String name, String nb) {
|
||||
this.name = name; this.hashCode = hashCode; this.nb = nb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof Town)) return false;
|
||||
return ((Town)o).name.equals(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name+" "+hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public class HashTest {
|
||||
Map<Town,Town> hashmap;
|
||||
List<Town> towns;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
towns = new LinkedList<>();
|
||||
towns.add(new Town(5,"Bari","BA"));
|
||||
towns.add(new Town(8,"Bologna","BO"));
|
||||
towns.add(new Town(3,"Catania","CA"));
|
||||
towns.add(new Town(9,"Firenze","FI"));
|
||||
towns.add(new Town(0,"Genova","GV"));
|
||||
towns.add(new Town(12,"Milano","MI"));
|
||||
towns.add(new Town(7,"Napoli","NA"));
|
||||
towns.add(new Town(7,"Palermo","PA"));
|
||||
towns.add(new Town(7,"Roma","RM"));
|
||||
towns.add(new Town(5,"Torino","TO"));
|
||||
hashmap = new MyHashtable<>(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.put(t0,t0);
|
||||
Town t1 = hashmap.get(t0);
|
||||
assertEquals(t0,t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd2() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
Town t1 = towns.get(1);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t1,t1);
|
||||
Town t2 = hashmap.get(t0);
|
||||
assertEquals(t0,t2);
|
||||
t2 = hashmap.get(t1);
|
||||
assertEquals(t1,t2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd3() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.remove(t0);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t0,t0);
|
||||
assertEquals(1, hashmap.size());
|
||||
Town t1 = hashmap.get(t0);
|
||||
assertEquals(t0,t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd4() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t0,t0);
|
||||
assertEquals(1, hashmap.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
hashmap.clear();
|
||||
assertEquals(0, hashmap.size());
|
||||
testAdd2();
|
||||
assertEquals(2, hashmap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
Town t1 = towns.get(1);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.remove(t0);
|
||||
assertEquals(0, hashmap.size());
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.remove(t1);
|
||||
assertEquals(1, hashmap.size());
|
||||
hashmap.remove(t0);
|
||||
assertEquals(0, hashmap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompetitor() {
|
||||
try {
|
||||
Competitor c1 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c2 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c3 = new Competitor(1,"Röthlin Viktor",75,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c4 = new Competitor(1,"Röthlin Pavel",74,"Magglingen/Macolin","2:11:05.0");
|
||||
assertEquals("test1",c1,c2);
|
||||
assertTrue("test2",c1.compareTo(c2) == 0);
|
||||
assertFalse("test3",c1.compareTo(c3) == 0);
|
||||
assertTrue("test4",c1.hashCode() == c2.hashCode());
|
||||
assertFalse("test5",c1.hashCode() == c3.hashCode());
|
||||
assertFalse("test6",c1.hashCode() == c4.hashCode());
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixed() {
|
||||
hashmap.clear();
|
||||
Map<Town,Town> hashmap2 = new HashMap<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Town c = towns.get((int)(Math.random()*towns.size()));
|
||||
// System.out.println(""+ c);
|
||||
int op = (int)(Math.random()*2);
|
||||
switch (op) {
|
||||
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
|
||||
case 1 : hashmap.remove(c); hashmap2.remove(c); break;
|
||||
}
|
||||
}
|
||||
assertEquals(hashmap2.size(), hashmap.size());
|
||||
for (Town t : towns) {
|
||||
Town c1 = hashmap.get(t);
|
||||
Town c2 = hashmap2.get(t);
|
||||
assertEquals(c1,c2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedWithOveflow() {
|
||||
Map<Town,Town> hashmap = new MyHashtable<>(4);
|
||||
Map<Town,Town> hashmap2 = new HashMap<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Town c = towns.get((int)(Math.random()*towns.size()));
|
||||
// System.out.println(""+ c);
|
||||
int op = (int)(Math.random()*2);
|
||||
switch (op) {
|
||||
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
|
||||
case 1 : hashmap.remove(c); hashmap2.remove(c); break;
|
||||
}
|
||||
}
|
||||
assertEquals(hashmap2.size(), hashmap.size());
|
||||
for (Town t : towns) {
|
||||
Town c1 = hashmap.get(t);
|
||||
Town c2 = hashmap2.get(t);
|
||||
assertEquals(c1,c2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.*;
|
||||
|
||||
class Town {
|
||||
int hashCode;
|
||||
String name;
|
||||
String nb;
|
||||
Town (int hashCode, String name, String nb) {
|
||||
this.name = name; this.hashCode = hashCode; this.nb = nb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof Town)) return false;
|
||||
return ((Town)o).name.equals(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name+" "+hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public class HashTest {
|
||||
Map<Town,Town> hashmap;
|
||||
List<Town> towns;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
towns = new LinkedList<>();
|
||||
towns.add(new Town(5,"Bari","BA"));
|
||||
towns.add(new Town(8,"Bologna","BO"));
|
||||
towns.add(new Town(3,"Catania","CA"));
|
||||
towns.add(new Town(9,"Firenze","FI"));
|
||||
towns.add(new Town(0,"Genova","GV"));
|
||||
towns.add(new Town(12,"Milano","MI"));
|
||||
towns.add(new Town(7,"Napoli","NA"));
|
||||
towns.add(new Town(7,"Palermo","PA"));
|
||||
towns.add(new Town(7,"Roma","RM"));
|
||||
towns.add(new Town(5,"Torino","TO"));
|
||||
hashmap = new MyHashtable<>(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.put(t0,t0);
|
||||
Town t1 = hashmap.get(t0);
|
||||
assertEquals(t0,t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd2() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
Town t1 = towns.get(1);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t1,t1);
|
||||
Town t2 = hashmap.get(t0);
|
||||
assertEquals(t0,t2);
|
||||
t2 = hashmap.get(t1);
|
||||
assertEquals(t1,t2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd3() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.remove(t0);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t0,t0);
|
||||
assertEquals(1, hashmap.size());
|
||||
Town t1 = hashmap.get(t0);
|
||||
assertEquals(t0,t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd4() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.put(t0,t0);
|
||||
assertEquals(1, hashmap.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
hashmap.clear();
|
||||
assertEquals(0, hashmap.size());
|
||||
testAdd2();
|
||||
assertEquals(2, hashmap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
hashmap.clear();
|
||||
Town t0 = towns.get(0);
|
||||
Town t1 = towns.get(1);
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.remove(t0);
|
||||
assertEquals(0, hashmap.size());
|
||||
hashmap.put(t0,t0);
|
||||
hashmap.remove(t1);
|
||||
assertEquals(1, hashmap.size());
|
||||
hashmap.remove(t0);
|
||||
assertEquals(0, hashmap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompetitor() {
|
||||
try {
|
||||
Competitor c1 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c2 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c3 = new Competitor(1,"Röthlin Viktor",75,"Magglingen/Macolin","2:11:05.0");
|
||||
Competitor c4 = new Competitor(1,"Röthlin Pavel",74,"Magglingen/Macolin","2:11:05.0");
|
||||
assertEquals("test1",c1,c2);
|
||||
assertTrue("test2",c1.compareTo(c2) == 0);
|
||||
assertFalse("test3",c1.compareTo(c3) == 0);
|
||||
assertTrue("test4",c1.hashCode() == c2.hashCode());
|
||||
assertFalse("test5",c1.hashCode() == c3.hashCode());
|
||||
assertFalse("test6",c1.hashCode() == c4.hashCode());
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixed() {
|
||||
hashmap.clear();
|
||||
Map<Town,Town> hashmap2 = new HashMap<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Town c = towns.get((int)(Math.random()*towns.size()));
|
||||
// System.out.println(""+ c);
|
||||
int op = (int)(Math.random()*2);
|
||||
switch (op) {
|
||||
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
|
||||
case 1 : hashmap.remove(c); hashmap2.remove(c); break;
|
||||
}
|
||||
}
|
||||
assertEquals(hashmap2.size(), hashmap.size());
|
||||
for (Town t : towns) {
|
||||
Town c1 = hashmap.get(t);
|
||||
Town c2 = hashmap2.get(t);
|
||||
assertEquals(c1,c2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedWithOveflow() {
|
||||
Map<Town,Town> hashmap = new MyHashtable<>(4);
|
||||
Map<Town,Town> hashmap2 = new HashMap<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Town c = towns.get((int)(Math.random()*towns.size()));
|
||||
// System.out.println(""+ c);
|
||||
int op = (int)(Math.random()*2);
|
||||
switch (op) {
|
||||
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
|
||||
case 1 : hashmap.remove(c); hashmap2.remove(c); break;
|
||||
}
|
||||
}
|
||||
assertEquals(hashmap2.size(), hashmap.size());
|
||||
for (Town t : towns) {
|
||||
Town c1 = hashmap.get(t);
|
||||
Town c2 = hashmap2.get(t);
|
||||
assertEquals(c1,c2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user