⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 olympicgamestest.java

📁 A system to manage the competitions of the XXth Olympic Games.
💻 JAVA
字号:
import junit.framework.TestCase;import games.*;

public class OlympicGamesTest extends TestCase {
	
	public void testCompetition() throws Exception {
		
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		assertEquals( "San Sicario", games.getVenue("Ladies' Downhill") );
		assertEquals("Cesana", games.getVenue("Bobsleigh Four-Man") );
	}
	
	public void testNoSuchCompetition() throws Exception {
		
		OlympicGames games = new OlympicGames();
		
		games.addCompetition("Bobsleigh Four-Man",       "Cesana");

		try {			
			games.getVenue("dummy");
            		fail("Should raise a NoSuchCompetition exception");
        	} catch (NoSuchCompetition expected) {
            		assertTrue(true);
        	}
	}	

	public void testAthlete() throws Exception {
		
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		games.addAthlete("Ladies' Downhill", "Mary Jones",   34, "England");
		games.addAthlete("Ladies' Downhill", "Carla Moro",   12, "Italy");
		games.addAthlete("Ladies' Downhill", "Claire Benot", 75, "France");

		assertTrue(games.getName("Ladies' Downhill", 75).indexOf("Benot")>=0);
	}
	
	public void testDummyAthleteInExistingCompetition() throws Exception {
		
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		games.addAthlete("Ladies' Downhill", "Mary Jones",   34, "England");
		games.addAthlete("Ladies' Downhill", "Carla Moro",   12, "Italy");
		games.addAthlete("Ladies' Downhill", "Claire Benot", 75, "France");

		assertEquals(games.getName("Ladies' Downhill", -1), "");
	}
	
	public void testExistingAthleteInDummyCompetition() throws Exception {
		
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		games.addAthlete("Ladies' Downhill", "Mary Jones",   34, "England");
		games.addAthlete("Ladies' Downhill", "Carla Moro",   12, "Italy");
		games.addAthlete("Ladies' Downhill", "Claire Benot", 75, "France");

		assertEquals(games.getName("dummy", 75), "");
	}	
	
	public void testOrder() throws Exception {
		
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		games.addAthlete("Ladies' Downhill", "Mary Jones",   34, "England");
		games.addAthlete("Ladies' Downhill", "Carla Moro",   12, "Italy");
		games.addAthlete("Ladies' Downhill", "Claire Benot", 75, "France");

		games.setTime("Ladies' Downhill", 12, 106);
		games.setTime("Ladies' Downhill", 34, 145);
		games.setTime("Ladies' Downhill", 75, 103);

		String s = games.getOrder("Ladies' Downhill");		assertTrue(s.indexOf("Benot")>=0);
		assertTrue(s.indexOf("Benot") < s.indexOf("Moro"));
		assertTrue(s.indexOf("Moro") < s.indexOf("Jones"));
	}
	
	public void testCount() throws Exception {
		OlympicGames games = new OlympicGames();

		games.addCompetition("Bobsleigh Four-Man",       "Cesana");
		games.addCompetition("Ladies' Downhill",         "San Sicario");
		games.addCompetition("Ladies's 15 km Classical", "Pragelato");

		games.addAthlete("Ladies' Downhill", "Mary Jones",   34, "England");
		games.addAthlete("Ladies' Downhill", "Carla Moro",   12, "Italy");
		games.addAthlete("Ladies' Downhill", "Claire Benot", 75, "France");
		
		games.addAthlete("Ladies's 15 km Classical", "Claire Benot", 67, "France");

		assertEquals(games.count("Claire Benot"), 2);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -