summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiorgi Beriashvili <giorgi.beriashvili@outlook.com>2020-10-05 02:26:05 +0400
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-05 07:15:09 +0200
commitd2bae54ed0249c276118ba85025cd8d3d1d7b6c9 (patch)
tree595fcd85a43267ae330bed49eda4b6a81042ac7c /tests
parent501c369f39eb4a8d0eac667bc021b0075e478456 (diff)
Add C-Sharp (C#) syntax highlighting test files
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/C-Sharp/Stack.cs64
-rw-r--r--tests/syntax-tests/source/C-Sharp/Stack.cs64
2 files changed, 128 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/C-Sharp/Stack.cs b/tests/syntax-tests/highlighted/C-Sharp/Stack.cs
new file mode 100644
index 00000000..be595c31
--- /dev/null
+++ b/tests/syntax-tests/highlighted/C-Sharp/Stack.cs
@@ -0,0 +1,64 @@
+namespace StackImplementation
+{
+ internal class Stack<T>
+ {
+ private int _top;
+ private const int Capacity = 4;
+ private readonly T[] _stack = new T[Capacity];
+
+ public Stack()
+ {
+ _top = -1;
+ }
+
+ private bool IsEmpty()
+ {
+ return _top < 0;
+ }
+ private bool IsFull()
+ {
+ return _top == Capacity - 1;
+ }
+
+ public void Peek()
+ {
+ System.Console.WriteLine(!IsEmpty() ? $"The topmost element is: {_stack[_top]}" : "The stack is empty.");
+ }
+
+ public T Pop()
+ {
+ return !IsEmpty() ? _stack[_top--] : default;
+ }
+
+ public void Push(T element)
+ {
+ if (!IsFull())
+ {
+ _stack[++_top] = element;
+ }
+ else
+ {
+ System.Console.WriteLine("Cannot push - the stack is full.");
+ }
+ }
+
+ public override string ToString()
+ {
+ if (IsEmpty())
+ {
+ return "The stack is empty.";
+ }
+
+ var depiction = "";
+
+ for (var index = 0; index < _top; index++)
+ {
+ depiction += _stack[index].ToString() + ' ';
+ }
+
+ depiction += _stack[_top].ToString();
+
+ return $"Stack: [{depiction}]";
+ }
+ }
+}
diff --git a/tests/syntax-tests/source/C-Sharp/Stack.cs b/tests/syntax-tests/source/C-Sharp/Stack.cs
new file mode 100644
index 00000000..9532faef
--- /dev/null
+++ b/tests/syntax-tests/source/C-Sharp/Stack.cs
@@ -0,0 +1,64 @@
+namespace StackImplementation
+{
+ internal class Stack<T>
+ {
+ private int _top;
+ private const int Capacity = 4;
+ private readonly T[] _stack = new T[Capacity];
+
+ public Stack()
+ {
+ _top = -1;
+ }
+
+ private bool IsEmpty()
+ {
+ return _top < 0;
+ }
+ private bool IsFull()
+ {
+ return _top == Capacity - 1;
+ }
+
+ public void Peek()
+ {
+ System.Console.WriteLine(!IsEmpty() ? $"The topmost element is: {_stack[_top]}" : "The stack is empty.");
+ }
+
+ public T Pop()
+ {
+ return !IsEmpty() ? _stack[_top--] : default;
+ }
+
+ public void Push(T element)
+ {
+ if (!IsFull())
+ {
+ _stack[++_top] = element;
+ }
+ else
+ {
+ System.Console.WriteLine("Cannot push - the stack is full.");
+ }
+ }
+
+ public override string ToString()
+ {
+ if (IsEmpty())
+ {
+ return "The stack is empty.";
+ }
+
+ var depiction = "";
+
+ for (var index = 0; index < _top; index++)
+ {
+ depiction += _stack[index].ToString() + ' ';
+ }
+
+ depiction += _stack[_top].ToString();
+
+ return $"Stack: [{depiction}]";
+ }
+ }
+}