-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a11c641
commit 33631d5
Showing
6 changed files
with
256 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
# Concordion.NET | ||
|
||
* Dependencies: NUnit | ||
* NuGet: https://www.nuget.org/packages/Concordion.NET/ | ||
* Source: https://github.com/concordion/concordion.net |
This file contains 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,29 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:concordion="http://www.concordion.org/2007/concordion"> | ||
<head> | ||
<meta content="text/html; charset=utf-8" http-equiv="content-type" /> | ||
</head> | ||
<body> | ||
<h1>Stack</h1> | ||
<pre> | ||
In order to support last-in-first-out (LIFO) operations | ||
As an developer | ||
I want to use a stack | ||
</pre> | ||
|
||
<h2>Empty</h2> | ||
<p concordion:execute="GivenAnEmptyStack()">Given an empty stack</p> | ||
<p concordion:assert-true="IsEmpty()">Then it has no elements</p> | ||
<p concordion:assert-true="ShouldThrowWhenPop()">And it throws an exception when calling pop</p> | ||
<p concordion:assert-true="ShouldThrowWhenPeek()">And it throws an exception when calling peek</p> | ||
|
||
<h2>Not empty</h2> | ||
<p concordion:execute="GivenANonEmptyStack()">Given a non empty stack</p> | ||
<p concordion:execute="#result = Peek()">When calling peek</p> | ||
<p concordion:assert-true="#result == TopElement">Then it returns the top element</p> | ||
<p concordion:assert-true="Contains(#result)">But it does not remove the top element</p> | ||
<p concordion:execute="#result = Pop()">When calling pop</p> | ||
<p concordion:assert-true="#result == TopElement">Then it returns the top element</p> | ||
<p concordion:assert-true="DoesNotContain(#result)">And it removes the top element</p> | ||
</body> | ||
</html> |
This file contains 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,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Concordion.NET.Integration; | ||
using Concordion.Runners.NUnit; | ||
using NUnit.Framework; | ||
|
||
namespace ConductOfCode.Concordion | ||
{ | ||
[TestFixture] | ||
[ConcordionTest] | ||
public class StackTest : ExecutableSpecification | ||
{ | ||
private Stack<int> stack; | ||
|
||
public int TopElement => 3; | ||
|
||
// Empty | ||
|
||
public void GivenAnEmptyStack() | ||
{ | ||
stack = new Stack<int>(); | ||
} | ||
|
||
public bool IsEmpty() | ||
{ | ||
return stack.Count == 0; | ||
} | ||
|
||
public bool ShouldThrowWhenPop() | ||
{ | ||
return ShouldThrowWhen(() => stack.Pop()); | ||
} | ||
|
||
public bool ShouldThrowWhenPeek() | ||
{ | ||
return ShouldThrowWhen(() => stack.Peek()); | ||
} | ||
|
||
private bool ShouldThrowWhen(Action action) | ||
{ | ||
try | ||
{ | ||
action(); | ||
} | ||
catch | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
// Not empty | ||
|
||
public void GivenANonEmptyStack() | ||
{ | ||
stack = new Stack<int>(new[] { 1, 2, TopElement }); | ||
} | ||
|
||
public int Pop() | ||
{ | ||
return stack.Pop(); | ||
} | ||
|
||
public int Peek() | ||
{ | ||
return stack.Peek(); | ||
} | ||
|
||
public bool Contains(int value) | ||
{ | ||
return stack.Contains(value); | ||
} | ||
|
||
public bool DoesNotContain(int value) | ||
{ | ||
return !stack.Contains(value); | ||
} | ||
} | ||
} |
This file contains 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 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 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