-
-
Notifications
You must be signed in to change notification settings - Fork 368
add connect generator and modify class to accept array input #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,160 @@ | ||
using Xunit; | ||
using System.Linq; | ||
// This file was auto-generated based on version 1.0.0 of the canonical data. | ||
|
||
using Xunit; | ||
using System; | ||
|
||
public class ConnectTest | ||
{ | ||
private static string MakeBoard(string[] board) | ||
[Fact] | ||
public void An_empty_board_has_no_winner() | ||
{ | ||
return string.Join("\n", board.Select(x => x.Replace(" ", ""))); | ||
var board = new [] | ||
{ | ||
". . . . .", | ||
" . . . . .", | ||
" . . . . .", | ||
" . . . . .", | ||
" . . . . ." | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.None, sut.Result()); | ||
} | ||
|
||
[Fact] | ||
public void Empty_board_has_no_winner() | ||
[Fact(Skip = "Remove to run test")] | ||
public void X_can_win_on_a_1x1_board() | ||
{ | ||
var board = new [] | ||
{ | ||
"X" | ||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.Black, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void O_can_win_on_a_1x1_board() | ||
{ | ||
var lines = new[] | ||
{ | ||
". . . . . ", | ||
" . . . . . ", | ||
" . . . . . ", | ||
" . . . . . ", | ||
" . . . . ." | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.None, board.Result()); | ||
var board = new [] | ||
{ | ||
"O" | ||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.White, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_by_one_board_with_black_stone() | ||
public void Only_edges_does_not_make_a_winner() | ||
{ | ||
var lines = new[] { "X" }; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.Black, board.Result()); | ||
var board = new [] | ||
{ | ||
"O O O X", | ||
" X . . X", | ||
" X . . X", | ||
" X O O O" | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.None, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_by_one_board_with_white_stone() | ||
public void Illegal_diagonal_does_not_make_a_winner() | ||
{ | ||
var lines = new[] { "O" }; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.White, board.Result()); | ||
var board = new [] | ||
{ | ||
"X O . .", | ||
" O X X X", | ||
" O X O .", | ||
" . O X .", | ||
" X X O O" | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.None, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Convoluted_path() | ||
public void Nobody_wins_crossing_adjacent_angles() | ||
{ | ||
var lines = new[] | ||
{ | ||
". X X . . ", | ||
" X . X . X ", | ||
" . X . X . ", | ||
" . X X . . ", | ||
" O O O O O" | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.Black, board.Result()); | ||
var board = new [] | ||
{ | ||
"X . . .", | ||
" . X O .", | ||
" O . X O", | ||
" . O . X", | ||
" . . O ." | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.None, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Rectangle_black_wins() | ||
public void X_wins_crossing_from_left_to_right() | ||
{ | ||
var lines = new[] | ||
{ | ||
". O . . ", | ||
" O X X X ", | ||
" O X O . ", | ||
" X X O X ", | ||
" . O X ." | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.Black, board.Result()); | ||
var board = new [] | ||
{ | ||
". O . .", | ||
" O X X X", | ||
" O X O .", | ||
" X X O X", | ||
" . O X ." | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.Black, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Rectangle_white_wins() | ||
public void O_wins_crossing_from_top_to_bottom() | ||
{ | ||
var lines = new[] | ||
{ | ||
". O . . ", | ||
" O X X X ", | ||
" O O O . ", | ||
" X X O X ", | ||
" . O X ." | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.White, board.Result()); | ||
var board = new [] | ||
{ | ||
". O . .", | ||
" O X X X", | ||
" O O O .", | ||
" X X O X", | ||
" . O X ." | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.White, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Spiral_black_wins() | ||
public void X_wins_using_a_convoluted_path() | ||
{ | ||
var lines = new[] | ||
{ | ||
"OXXXXXXXX", | ||
"OXOOOOOOO", | ||
"OXOXXXXXO", | ||
"OXOXOOOXO", | ||
"OXOXXXOXO", | ||
"OXOOOXOXO", | ||
"OXXXXXOXO", | ||
"OOOOOOOXO", | ||
"XXXXXXXXO" | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.Black, board.Result()); | ||
var board = new [] | ||
{ | ||
". X X . .", | ||
" X . X . X", | ||
" . X . X .", | ||
" . X X . .", | ||
" O O O O O" | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.Black, sut.Result()); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Spiral_nobody_wins() | ||
public void X_wins_using_a_spiral_path() | ||
{ | ||
var lines = new[] | ||
{ | ||
"OXXXXXXXX", | ||
"OXOOOOOOO", | ||
"OXOXXXXXO", | ||
"OXOXOOOXO", | ||
"OXOX.XOXO", | ||
"OXOOOXOXO", | ||
"OXXXXXOXO", | ||
"OOOOOOOXO", | ||
"XXXXXXXXO" | ||
}; | ||
var board = new Connect(MakeBoard(lines)); | ||
Assert.Equal(ConnectWinner.None, board.Result()); | ||
var board = new [] | ||
{ | ||
"O X X X X X X X X", | ||
" O X O O O O O O O", | ||
" O X O X X X X X O", | ||
" O X O X O O O X O", | ||
" O X O X X X O X O", | ||
" O X O O O X O X O", | ||
" O X X X X X O X O", | ||
" O O O O O O O X O", | ||
" X X X X X X X X O" | ||
|
||
} ; | ||
var sut = new Connect(board); | ||
Assert.Equal(ConnectWinner.Black, sut.Result()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Generators.Input; | ||
using Generators.Output; | ||
|
||
namespace Generators.Exercises | ||
{ | ||
public class Connect : Exercise | ||
{ | ||
protected override void UpdateCanonicalData(CanonicalData canonicalData) | ||
{ | ||
foreach (var canonicalDataCase in canonicalData.Cases) | ||
{ | ||
canonicalDataCase.UseVariablesForConstructorParameters = true; | ||
canonicalDataCase.SetConstructorInputParameters("board"); | ||
canonicalDataCase.Property = "result"; | ||
canonicalDataCase.Properties["board"] = ToMultiLineString(canonicalDataCase.Properties["board"]); | ||
|
||
//convert to enum | ||
switch (canonicalDataCase.Properties["expected"]) | ||
{ | ||
case "X": | ||
canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.Black"); | ||
break; | ||
case "O": | ||
canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.White"); | ||
break; | ||
case "": | ||
canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.None"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
protected override HashSet<string> AddAdditionalNamespaces() | ||
{ | ||
return new HashSet<string> | ||
{ | ||
typeof(Environment).Namespace | ||
}; | ||
} | ||
|
||
private UnescapedValue ToMultiLineString(string[] input) | ||
{ | ||
const string template = @"new [] | ||
{ | ||
{% if input.size == 0 %}string.Empty{% else %}{% for item in {{input}} %}{% if forloop.length == 1 %}""{{item}}""{% break %}{% endif %}""{{item}}""{% if forloop.last == false %},{% endif %} | ||
{% endfor %} | ||
} {% endif %}"; | ||
|
||
return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you perhaps use less indentation? Something like this looks better IMHO: