소스 검색

finished part 7

Luis Romero 6 년 전
부모
커밋
ee4c276c2b
2개의 변경된 파일65개의 추가작업 그리고 33개의 파일을 삭제
  1. 33
    1
      src/main/java/Pair/Pair.java
  2. 32
    32
      src/test/java/Pair/PairTest.java

+ 33
- 1
src/main/java/Pair/Pair.java 파일 보기

@@ -7,6 +7,38 @@ package Pair;
7 7
  * min -> returns the minimum of the pair
8 8
  * max -> returns the maximum of the pair
9 9
  */
10
-public class Pair {
10
+public class Pair<E extends Comparable> {
11
+
12
+    private E e1;
13
+    private E e2;
14
+
15
+    public Pair(E e1, E e2) {
16
+        this.e1 = e1;
17
+        this.e2 = e2;
18
+    }
19
+
20
+    public E getFirst() {
21
+        return e1;
22
+    }
23
+
24
+    public E getSecond() {
25
+        return e2;
26
+    }
27
+
28
+    public E min() {
29
+        if (e1.compareTo(e2) < 0) {
30
+            return e1;
31
+        } else {
32
+            return e2;
33
+        }
34
+    }
35
+
36
+    public E max() {
37
+        if (e1.compareTo(e2) < 0) {
38
+            return e2;
39
+        } else {
40
+            return e1;
41
+        }
42
+    }
11 43
 
12 44
 }

+ 32
- 32
src/test/java/Pair/PairTest.java 파일 보기

@@ -1,32 +1,32 @@
1
-//package Pair;
2
-//
3
-//import org.junit.Test;
4
-//import org.junit.Assert;
5
-//
6
-//public class PairTest {
7
-//
8
-//    @Test
9
-//    public void testGetters() throws Exception {
10
-//        // Given a pair with "Foo" and "Bar"
11
-//        Pair<String> p = new Pair<String>("Foo", "Bar");
12
-//        // When getFirst and getSecond are called, they should be returned.
13
-//        Assert.assertEquals("Foo", p.getFirst());
14
-//        Assert.assertEquals("Bar",  p.getSecond());
15
-//    }
16
-//
17
-//    @Test
18
-//    public void testMin() throws Exception {
19
-//        // Given a pair with two values
20
-//        Pair<Double> p = new Pair<Double>(1.23, 2.34);
21
-//        // When p.min() is called, the smallest should be returned.
22
-//        Assert.assertEquals(new Double(1.23), p.min());
23
-//    }
24
-//
25
-//    @Test
26
-//    public void testMax() throws Exception {
27
-//        // Given a pair with two values
28
-//        Pair<Double> p = new Pair<Double>(1.23, 2.34);
29
-//        // When p.max() is called, the largest should be returned.
30
-//        Assert.assertEquals(new Double(2.34), p.max());
31
-//    }
32
-//}
1
+package Pair;
2
+
3
+import org.junit.Test;
4
+import org.junit.Assert;
5
+
6
+public class PairTest {
7
+
8
+    @Test
9
+    public void testGetters() throws Exception {
10
+        // Given a pair with "Foo" and "Bar"
11
+        Pair<String> p = new Pair<String>("Foo", "Bar");
12
+        // When getFirst and getSecond are called, they should be returned.
13
+        Assert.assertEquals("Foo", p.getFirst());
14
+        Assert.assertEquals("Bar",  p.getSecond());
15
+    }
16
+
17
+    @Test
18
+    public void testMin() throws Exception {
19
+        // Given a pair with two values
20
+        Pair<Double> p = new Pair<Double>(1.23, 2.34);
21
+        // When p.min() is called, the smallest should be returned.
22
+        Assert.assertEquals(new Double(1.23), p.min());
23
+    }
24
+
25
+    @Test
26
+    public void testMax() throws Exception {
27
+        // Given a pair with two values
28
+        Pair<Double> p = new Pair<Double>(1.23, 2.34);
29
+        // When p.max() is called, the largest should be returned.
30
+        Assert.assertEquals(new Double(2.34), p.max());
31
+    }
32
+}