Skip to content

Commit 8949bfe

Browse files
[LEET-133] add unit test for 133
1 parent f27e35c commit 8949bfe

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

leetcode-algorithms/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
|138|[Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/CopyListWithRandomPointer.java)| O(?)|O(?) | Medium|
213213
|137|[Single Number II](https://leetcode.com/problems/single-number-ii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/SingleNumberII.java)| O(n)|O(n) | Medium|
214214
|135|[Candy](https://leetcode.com/problems/candy/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/Candy.java)| O(n)|O(1) | Hard| Greedy
215-
|133|[Clone Graph](https://leetcode.com/problems/clone-graph/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/CloneGraph.java)| O(n)|O(n) | Medium| HashMap, BFS
215+
|133|[Clone Graph](https://leetcode.com/problems/clone-graph/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/CloneGraph.java)| O(n)|O(n) | Medium| HashMap, BFS, Graph
216216
|132|[Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ImplementQueueUsingStacks.java)| O(n)|O(n) | Easy| Stack, Queue
217217
|130|[Surrounded Regions](https://leetcode.com/problems/surrounded-regions/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/SurroundedRegionsBFS.java)| O(?)|O(?) | Medium|
218218
|129|[Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/SumRootToLeafNumbers.java)| O(n)|O(h) | Medium| DFS

leetcode-algorithms/src/main/java/com/stevesun/common/classes/UndirectedGraphNode.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,24 @@
99
public class UndirectedGraphNode {
1010
public int label;
1111
public List<UndirectedGraphNode> neighbors;
12+
13+
@Override
14+
public boolean equals(Object o) {
15+
if (this == o) return true;
16+
if (o == null || getClass() != o.getClass()) return false;
17+
18+
UndirectedGraphNode that = (UndirectedGraphNode) o;
19+
20+
if (label != that.label) return false;
21+
return neighbors != null ? neighbors.equals(that.neighbors) : that.neighbors == null;
22+
}
23+
24+
@Override
25+
public int hashCode() {
26+
int result = label;
27+
result = 31 * result + (neighbors != null ? neighbors.hashCode() : 0);
28+
return result;
29+
}
30+
1231
public UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
1332
}

leetcode-algorithms/src/main/java/com/stevesun/solutions/MinimumUniqueWordAbbreviation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public String minAbbreviation(String target, String[] dictionary) {
2424
* This is NOT going to work due to TLE.
2525
* Tags are backtracking and bit manipulation.*/
2626
return null;
27+
2728
}
2829

2930
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.stevesun;
2+
3+
import com.stevesun.common.classes.UndirectedGraphNode;
4+
import com.stevesun.solutions.CloneGraph;
5+
import org.junit.Before;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import static junit.framework.Assert.assertEquals;
10+
11+
/**
12+
* Created by stevesun on 1/15/17.
13+
*/
14+
public class CloneGraphTest {
15+
private static CloneGraph test;
16+
private static UndirectedGraphNode expected;
17+
private static UndirectedGraphNode actual;
18+
19+
@BeforeClass
20+
public static void setup(){
21+
test = new CloneGraph();
22+
}
23+
24+
@Before
25+
public void setupForEachTest(){
26+
expected = null;
27+
actual = null;
28+
}
29+
30+
@Test
31+
public void test1(){
32+
UndirectedGraphNode node0 = new UndirectedGraphNode(0);
33+
UndirectedGraphNode node1 = new UndirectedGraphNode(1);
34+
UndirectedGraphNode node2 = new UndirectedGraphNode(2);
35+
node0.neighbors.add(node1);
36+
node0.neighbors.add(node2);
37+
node1.neighbors.add(node2);
38+
39+
expected = node0;
40+
actual = test.cloneGraph(expected);
41+
assertEquals(expected, actual);
42+
}
43+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy