作業部屋の使い方を試しています。
(empty log message)
| @@ -4,6 +4,8 @@ | ||
| 4 | 4 | * and open the template in the editor. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | +package sample; | |
| 8 | + | |
| 7 | 9 | import junit.framework.TestCase; |
| 8 | 10 | import sample.Vectors; |
| 9 | 11 |
| @@ -46,11 +48,13 @@ | ||
| 46 | 48 | */ |
| 47 | 49 | public void testScalarMultiplication() { |
| 48 | 50 | System.out.println("* VectorsJUnit3Test: testScalarMultiplication()"); |
| 51 | + /* | |
| 49 | 52 | int[] a = null; |
| 50 | 53 | int[] b = null; |
| 51 | 54 | int expResult = 0; |
| 52 | 55 | int result = Vectors.scalarMultiplication(a, b); |
| 53 | 56 | assertEquals(expResult, result); |
| 57 | + */ | |
| 54 | 58 | assertEquals( 0, Vectors.scalarMultiplication(new int[] { 0, 0}, new int[] { 0, 0})); |
| 55 | 59 | assertEquals( 39, Vectors.scalarMultiplication(new int[] { 3, 4}, new int[] { 5, 6})); |
| 56 | 60 | assertEquals(-39, Vectors.scalarMultiplication(new int[] {-3, 4}, new int[] { 5,-6})); |
| @@ -58,7 +62,7 @@ | ||
| 58 | 62 | assertEquals(100, Vectors.scalarMultiplication(new int[] { 6, 8}, new int[] { 6, 8})); |
| 59 | 63 | |
| 60 | 64 | // TODO review the generated test code and remove the default call to fail. |
| 61 | - fail("The test case is a prototype."); | |
| 65 | + // fail("The test case is a prototype."); | |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | } |
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * To change this license header, choose License Headers in Project Properties. | |
| 3 | + * To change this template file, choose Tools | Templates | |
| 4 | + * and open the template in the editor. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +package sample; | |
| 8 | + | |
| 9 | +import org.junit.AfterClass; | |
| 10 | +import org.junit.BeforeClass; | |
| 11 | +import org.junit.Test; | |
| 12 | +import static org.junit.Assert.*; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * | |
| 16 | + * @author kgto | |
| 17 | + */ | |
| 18 | +public class VectorsJUnit4Test { | |
| 19 | + | |
| 20 | + public VectorsJUnit4Test() { | |
| 21 | + } | |
| 22 | + | |
| 23 | + /* 削除 | |
| 24 | + @BeforeClass | |
| 25 | + public static void setUpClass() { | |
| 26 | + } | |
| 27 | + | |
| 28 | + @AfterClass | |
| 29 | + public static void tearDownClass() { | |
| 30 | + } | |
| 31 | + */ | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Test of equal method, of class Vectors. | |
| 35 | + */ | |
| 36 | + @Test | |
| 37 | + public void testEqual() { | |
| 38 | + System.out.println("equal"); | |
| 39 | + int[] a = null; | |
| 40 | + int[] b = null; | |
| 41 | + boolean expResult = false; | |
| 42 | + boolean result = Vectors.equal(a, b); | |
| 43 | + assertEquals(expResult, result); | |
| 44 | + // TODO review the generated test code and remove the default call to fail. | |
| 45 | + fail("The test case is a prototype."); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Test of scalarMultiplication method, of class Vectors. | |
| 50 | + */ | |
| 51 | + @Test | |
| 52 | + public void testScalarMultiplication() { | |
| 53 | + System.out.println("scalarMultiplication"); | |
| 54 | + int[] a = null; | |
| 55 | + int[] b = null; | |
| 56 | + int expResult = 0; | |
| 57 | + int result = Vectors.scalarMultiplication(a, b); | |
| 58 | + assertEquals(expResult, result); | |
| 59 | + // TODO review the generated test code and remove the default call to fail. | |
| 60 | + fail("The test case is a prototype."); | |
| 61 | + } | |
| 62 | + | |
| 63 | +} |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | package sample; |
| 8 | 8 | |
| 9 | +import java.util.concurrent.TimeoutException; | |
| 9 | 10 | import junit.framework.TestCase; |
| 10 | 11 | |
| 11 | 12 | /** |
| @@ -33,6 +34,7 @@ | ||
| 33 | 34 | /** |
| 34 | 35 | * Test of concatWords method, of class Utils. |
| 35 | 36 | */ |
| 37 | + /* 削除 | |
| 36 | 38 | public void testConcatWords() { |
| 37 | 39 | System.out.println("concatWords"); |
| 38 | 40 | String[] words = null; |
| @@ -42,10 +44,16 @@ | ||
| 42 | 44 | // TODO review the generated test code and remove the default call to fail. |
| 43 | 45 | fail("The test case is a prototype."); |
| 44 | 46 | } |
| 47 | + */ | |
| 48 | + public void testHelloWorld() { | |
| 49 | + System.out.println("* UtilsJUnit3Test: test method 1 - testHelloWorld()"); | |
| 50 | + assertEquals("Hello, world!", Utils.concatWords("Hello", ", ", "world", "!")); | |
| 51 | + } | |
| 45 | 52 | |
| 46 | 53 | /** |
| 47 | 54 | * Test of computeFactorial method, of class Utils. |
| 48 | 55 | */ |
| 56 | + /* 削除 | |
| 49 | 57 | public void testComputeFactorial() { |
| 50 | 58 | System.out.println("computeFactorial"); |
| 51 | 59 | int number = 0; |
| @@ -55,10 +63,41 @@ | ||
| 55 | 63 | // TODO review the generated test code and remove the default call to fail. |
| 56 | 64 | fail("The test case is a prototype."); |
| 57 | 65 | } |
| 66 | + */ | |
| 67 | + public void testWithTimeout() throws InterruptedException, TimeoutException { | |
| 68 | + System.out.println("* UtilsJUnit3Test: test method 2 - testWithTimeout()"); | |
| 69 | + final int factorialOf = 1 + (int) (30000 * Math.random()); | |
| 70 | + System.out.println("computing " + factorialOf + '!'); | |
| 58 | 71 | |
| 72 | + Thread testThread = new Thread() { | |
| 73 | + public void run() { | |
| 74 | + System.out.println(factorialOf + "! = " + Utils.computeFactorial(factorialOf)); | |
| 75 | + } | |
| 76 | + }; | |
| 77 | + | |
| 78 | + testThread.start(); | |
| 79 | + Thread.sleep(1000); | |
| 80 | + testThread.interrupt(); | |
| 81 | + | |
| 82 | + if (testThread.isInterrupted()) { | |
| 83 | + throw new TimeoutException("the test took too long to complete"); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + public void testExpectedException() { | |
| 88 | + System.out.println("* UtilsJUnit3Test: test method 3 - testExpectedException()"); | |
| 89 | + try { | |
| 90 | + final int factorialOf = -5; | |
| 91 | + System.out.println(factorialOf + "! = " + Utils.computeFactorial(factorialOf)); | |
| 92 | + fail("IllegalArgumentException was expected"); | |
| 93 | + } catch (IllegalArgumentException ex) { | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 59 | 97 | /** |
| 60 | 98 | * Test of normalizeWord method, of class Utils. |
| 61 | 99 | */ |
| 100 | + /* 削除 | |
| 62 | 101 | public void testNormalizeWord() { |
| 63 | 102 | System.out.println("normalizeWord"); |
| 64 | 103 | String word = ""; |
| @@ -68,5 +107,11 @@ | ||
| 68 | 107 | // TODO review the generated test code and remove the default call to fail. |
| 69 | 108 | fail("The test case is a prototype."); |
| 70 | 109 | } |
| 110 | + */ | |
| 71 | 111 | |
| 112 | + public void DISABLED_testTemporarilyDisabled() throws Exception { | |
| 113 | + System.out.println("* UtilsJUnit3Test: test method 4 - checkExpectedException()"); | |
| 114 | + assertEquals("Malm\u00f6", Utils.normalizeWord("Malmo\u0308")); | |
| 115 | + } | |
| 116 | + | |
| 72 | 117 | } |