Advertisement
brentfisher-72

BFS Test ik correction

Apr 13th, 2024 (edited)
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | Source Code | 0 0
  1. package com.brent.ik.graphs;
  2.  
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5. import org.junit.jupiter.params.ParameterizedTest;
  6. import org.junit.jupiter.params.provider.Arguments;
  7. import org.junit.jupiter.params.provider.MethodSource;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.fasterxml.jackson.core.type.TypeReference;
  10.  
  11. import java.util.HashMap;
  12. import java.util.*;
  13. import java.util.stream.Stream;
  14.  
  15. import static com.brent.ik.graphs.BFS.*;
  16.  
  17. import static org.assertj.core.api.Assertions.assertThat;
  18.  
  19.  
  20. class BFSTest {
  21.  
  22.     public static class GraphData {
  23.         private int n;
  24.         private List<List<Integer>> edges;
  25.  
  26.         public int getN() {
  27.             return n;
  28.         }
  29.  
  30.         public void setN(int n) {
  31.             this.n = n;
  32.         }
  33.  
  34.         public List<List<Integer>> getEdges() {
  35.             return edges;
  36.         }
  37.  
  38.         public void setEdges(List<List<Integer>> edges) {
  39.             this.edges = edges;
  40.         }
  41.     }
  42.  
  43.     @Test
  44.     void shouldTraverseGraph_givenGraph() throws Exception {
  45.         var inputJson = """
  46.                 {
  47.                     "n": 6,
  48.                     "edges": [
  49.                     [0, 1],
  50.                     [0, 2],
  51.                     [0, 4],
  52.                     [2, 3]
  53.                     ]
  54.                 }
  55. """;
  56.         var expectedString = """
  57.                 [0, 1, 2, 4, 3, 5]
  58. """;       
  59.         var json = new ObjectMapper();
  60.         GraphData graphData = json.readValue(inputJson,GraphData.class);
  61.        
  62.         List<Integer> expected = json.readValue(expectedString, new TypeReference<List<Integer>>(){});
  63.         var actual = bfs_traversal(graphData.n,graphData.edges);
  64.         assertThat(actual).isEqualTo(expected);
  65.        
  66.     }
  67. }
  68. /**
  69. <T> T readValue(String content,
  70.                        com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
  71. */
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement