Skip to content

Instantly share code, notes, and snippets.

@TomasDrozdik
Created October 19, 2018 19:06
Show Gist options
  • Save TomasDrozdik/2aa26f89dfe6ea0ea31848432104d622 to your computer and use it in GitHub Desktop.
Save TomasDrozdik/2aa26f89dfe6ea0ea31848432104d622 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uloha4_ViceZarovnani;
namespace Uloha4ViceZarovnaniTests
{
[TestClass]
public class ReaderUT
{
[TestMethod]
public void ReadWord_EmptyInputTest()
{
var input = new System.IO.StringReader("");
Reader r = new Reader(input);
var output = new List<string>();
var referenceOutput = new List<string>();
while (!r.IsEof()) {
output.Add(r.ReadWord());
}
Assert.AreEqual(output.ToString(), referenceOutput.ToString());
}
[TestMethod]
public void ReadWord_SingleWordTest()
{
var input = new System.IO.StringReader("hello");
Reader r = new Reader(input);
var output = new List<string>();
string[] refOut = { "hello" };
var referenceOutput = new List<string>(refOut);
while (!r.IsEof()) {
output.Add(r.ReadWord());
}
Assert.AreEqual(output.ToString(), referenceOutput.ToString());
}
[TestMethod]
public void ReadWord_OneLineTest()
{
var input = new System.IO.StringReader("Hello world test. How are you?");
Reader r = new Reader(input);
var output = new List<string>();
string[] refOut = { "Hello", "world", "test.", "How", "are", "you?" };
var referenceOutput = new List<string>(refOut);
while (!r.IsEof()) {
output.Add(r.ReadWord());
}
Assert.AreEqual(output.ToString(), referenceOutput.ToString());
}
[TestMethod]
public void ReadWord_MultipleLineTest()
{
var input = new System.IO.StringReader(" Hello world test.\n\n How are you\n? \n");
Reader r = new Reader(input);
var output = new List<string>();
string[] refOut = { "Hello", "world", "test.", "How", "are", "you?" };
var referenceOutput = new List<string>();
while (!r.IsEof()) {
output.Add(r.ReadWord());
}
Assert.AreEqual(output.ToString(), referenceOutput.ToString());
}
}
}
using System;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uloha4_ViceZarovnani;
namespace Uloha4ViceZarovnaniTests
{
[TestClass]
public class WriterUT
{
[TestMethod]
public void WriteT()
{
var sw = new StringWriter(new StringBuilder());
var w = new Writer(sw);
var input = "Hello \nworld!";
w.Write(input);
Assert.AreEqual(input, sw.ToString());
}
[TestMethod]
public void WriteLineT()
{
var sw = new StringWriter(new StringBuilder());
var w = new Writer(sw);
var input = "Hello world!";
w.WriteLine(input);
string referenceOutput = "Hello world!" + Environment.NewLine;
Assert.AreEqual(referenceOutput, sw.ToString());
}
[TestMethod]
public void Write_HighlightT()
{
var sw = new StringWriter(new StringBuilder());
var w = new Writer(sw);
w.SetHighlightWhitespaces(true);
var input = "Hello \nworld!";
w.Write(input);
string referenceOutput = "Hello.<-\nworld!";
Assert.AreEqual(referenceOutput, sw.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment