File tree Expand file tree Collapse file tree 2 files changed +96
-0
lines changed Expand file tree Collapse file tree 2 files changed +96
-0
lines changed Original file line number Diff line number Diff line change 1+ package  grid
2+ 
3+ import  (
4+ 	"testing" 
5+ 
6+ 	"github.com/agrmohit/aoc/internal/inputs" 
7+ )
8+ 
9+ func  TestFindWordsInGrid (t  * testing.T ) {
10+ 	input  :=  `MMMSXXMASM 
11+ MSAMXMSMSA 
12+ AMXSXMAAMM 
13+ MSAMASMSMX 
14+ XMASAMXAMM 
15+ XXAMMXXAMA 
16+ SMSMSASXSS 
17+ SAXAMASAAA 
18+ MAMMMXMMMM 
19+ MXMXAXMASX` 
20+ 	want  :=  18 
21+ 
22+ 	characterGrid , _  :=  inputs .ExtractCharacterGrid (input )
23+ 	directions  :=  []SearchDirection {
24+ 		HorizontalForward ,
25+ 		HorizontalBackward ,
26+ 		VerticalDown ,
27+ 		VerticalUp ,
28+ 		DiagonalUpwardsLeft ,
29+ 		DiagonalUpwardsRight ,
30+ 		DiagonalDownwardsLeft ,
31+ 		DiagonalDownwardsRight ,
32+ 	}
33+ 	WordLocationList  :=  FindWordsInGrid (characterGrid , []string {"XMAS" }, directions )
34+ 	got  :=  len (WordLocationList )
35+ 
36+ 	if  got  !=  want  {
37+ 		t .Errorf ("got %v, want%v" , got , want )
38+ 	}
39+ }
Original file line number Diff line number Diff line change 1+ package  grid
2+ 
3+ import  (
4+ 	"testing" 
5+ 
6+ 	"github.com/agrmohit/aoc/internal/inputs" 
7+ )
8+ 
9+ func  TestFindSubgridsInGrid (t  * testing.T ) {
10+ 	input  :=  `.M.S...... 
11+ ..A..MSMS. 
12+ .M.S.MAA.. 
13+ ..A.ASMSM. 
14+ .M.S.M.... 
15+ .......... 
16+ S.S.S.S.S. 
17+ .A.A.A.A.. 
18+ M.M.M.M.M. 
19+ ..........` 
20+ 	want  :=  9 
21+ 
22+ 	characterGrid , _  :=  inputs .ExtractCharacterGrid (input )
23+ 
24+ 	subgrids  :=  [][][]byte {}
25+ 	subgridCount  :=  0 
26+ 
27+ 	subgrids  =  append (subgrids , [][]byte {
28+ 		{'M' , '.' , 'M' },
29+ 		{'.' , 'A' , '.' },
30+ 		{'S' , '.' , 'S' },
31+ 	})
32+ 	subgrids  =  append (subgrids , [][]byte {
33+ 		{'M' , '.' , 'S' },
34+ 		{'.' , 'A' , '.' },
35+ 		{'M' , '.' , 'S' },
36+ 	})
37+ 	subgrids  =  append (subgrids , [][]byte {
38+ 		{'S' , '.' , 'M' },
39+ 		{'.' , 'A' , '.' },
40+ 		{'S' , '.' , 'M' },
41+ 	})
42+ 	subgrids  =  append (subgrids , [][]byte {
43+ 		{'S' , '.' , 'S' },
44+ 		{'.' , 'A' , '.' },
45+ 		{'M' , '.' , 'M' },
46+ 	})
47+ 
48+ 	for  _ , subgrid  :=  range  subgrids  {
49+ 		subgridLocationList  :=  FindSubgridsInGrid (characterGrid , subgrid , '.' )
50+ 		subgridCount  +=  len (subgridLocationList )
51+ 	}
52+ 	got  :=  subgridCount 
53+ 
54+ 	if  got  !=  want  {
55+ 		t .Errorf ("got %v, want%v" , got , want )
56+ 	}
57+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments