public void IndexGet_CorrectIndex_ReturnsExpectedCharacter() { // Arrange var myStr = new MyString.MyString("Hello"); // Act + Assert Assert.Equal('o', myStr[4]); }
public void SubString_IncorrectRange_ThrowsException() { // Arrange var myStr = new MyString.MyString("Hello World"); // Act + Assert Assert.Throws <Exception>(() => myStr.SubString(7, 5)); }
public void IndexGet_IncorrectIndex_ThrowsException() { // Arrange var myStr = new MyString.MyString("Hello"); // Act + Assert Assert.Throws <IndexOutOfRangeException>(() => myStr[-1]); Assert.Throws <IndexOutOfRangeException>(() => myStr[5]); }
public void Constructor_NoArgs_CreatesEmptyMyString() { // Arrange + Act var myStr = new MyString.MyString(); // Assert Assert.Equal(0, myStr.Length); Assert.Equal(new char[0], myStr); }
public void Assignment_SomeClassInstance_NewInstanceIsSame() { // Arrange var a = new MyString.MyString("hey"); // Act var b = a; // Assignment reference // Act Assert.Same(a, b); }
public void IndexSet_CorrectIndex_CharAtIndexIsChanged() { // Arrange var myStr = new MyString.MyString("Hello") { [3] = 'a' }; // Assert Assert.Equal('a', myStr[3]); }
public void GetStringData_MyStringWithSomeData_ReturnsCharEnumerablePlusNullSymbol() { // Arrange const string someString = "Hello"; // Act var myStr = new MyString.MyString(someString); // Assert Assert.Equal(someString + "\0", myStr.GetStringData); }
public void Constructor_CharArrayWithNullCharacterAtCenter_CreatesMyStringWithSameCharacters() { // Arrange var chars = new[] { 'H', 'e', 'l', 'l', 'o', '\0', 'W', 'o', 'r', 'l', 'd' }; // Act var myStr = new MyString.MyString(chars); // Assert Assert.Equal(chars.Length, myStr.Length); Assert.Equal("Hello\0World", myStr); }
public void SubString_CorrectRange_ReturnsExpectedSubString() { // Arrange var myStr = new MyString.MyString("Hello World"); // Act var newStr = myStr.SubString(6, 5); // Assert Assert.Equal(5, newStr.Length); Assert.Equal("World", newStr); }
public void Constructor_OtherMyStringInstance_CreatesNewInstanceOfMyStringWithSameCharacters() { // Arrange + Act var myStr = new MyString.MyString(new[] { 'H', 'e', 'l', 'l', 'o' }); var copyStr = new MyString.MyString(myStr); // Assert Assert.NotSame(myStr, copyStr); Assert.Equal(myStr.Length, copyStr.Length); Assert.Equal(copyStr, myStr); }
public void Clear_NonEmptyString_StringIsEmptyNow() { // Arrange var myStr = new MyString.MyString("Hello"); // Act myStr.Clear(); // Assert Assert.Equal(0, myStr.Length); Assert.Equal(string.Empty, myStr); }
public void Constructor_RegularString_CreatesMyStringWithSameCharacters() { // Arrange const string someString = "Hello"; // Act var myStr = new MyString.MyString(someString); // Assert Assert.Equal(someString.Length, myStr.Length); Assert.Equal(new[] { 'H', 'e', 'l', 'l', 'o' }, myStr); }
public void Concat_CharArrayWithMyString_ReturnsCombinedMyString() { // Arrange var a = new[] { 'h', 'e', 'y', ' ' }; var b = new MyString.MyString("world"); // Act var c = a + b; // Assert Assert.Equal(a.Length + b.Length, c.Length); Assert.Equal("hey world", c); }
public void Concat_StringWithMyString_ReturnsCombinedMyString() { // Arrange const string a = "hey"; var b = new MyString.MyString(" world"); // Act var c = a + b; // Assert Assert.Equal(a.Length + b.Length, c.Length); Assert.Equal("hey world", c); }
public void Constructor_CharArray_CreatesMyStringWithSameCharacters() { // Arrange var chars = new[] { 'H', 'e', 'l', 'l', 'o' }; // Act var myStr = new MyString.MyString(chars); // Assert Assert.Equal(chars.Length, myStr.Length); Assert.Equal(chars, myStr); Assert.Equal("Hello", myStr); }
public void Concat_MyStringWithMyString_ReturnsCombinedMyString() { // Arrange var a = new MyString.MyString("hey "); var b = new MyString.MyString(new[] { 'w', 'o', 'r', 'l', 'd' }); // Act var c = a + b; // Assert Assert.Equal(a.Length + b.Length, c.Length); Assert.Equal("hey world", c); }
public void Constructor_CharArrayWithLength_CreatesMyStringWithFirstNChars() { // Arrange const int length = 4; var chars = new[] { 'H', 'e', 'l', 'l', 'o' }; // Act var myStr = new MyString.MyString(chars, length); // Assert Assert.Equal(length, myStr.Length); Assert.Equal(new[] { 'H', 'e', 'l', 'l' }, myStr); }
public void Comparison_TwoDifferentStrings_ExpectedOperatorsBehaviour() { // Arrange var a = new MyString.MyString("Hello"); var b = new MyString.MyString("Hell"); // Act + Assert Assert.False(a == b); Assert.True(a != b); Assert.True(a >= b); Assert.False(a <= b); Assert.True(a > b); Assert.False(a < b); }
public void WriteToStream_StringWithSomeTextToFileStream_WritesSameTextToTheFile() { // Arrange const string filePath = "temp.txt"; const string fileText = "Hello"; var myString = new MyString.MyString("Hello"); // Act using (var fsa = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { myString.WriteToStream(fsa); } var actualFileText = File.ReadAllText(filePath); File.Delete(filePath); // Assert Assert.Equal(fileText, actualFileText); }
public void ReadFromStream_FileStreamWithText_StringIsFilledWithTheText() { // Arrange const string filePath = "temp.txt"; const string fileText = "Hello world and everyone here!"; File.WriteAllText(filePath, fileText); var myString = new MyString.MyString(); // Act using (var fsa = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { myString.ReadFromStream(fsa); } File.Delete(filePath); // Assert Assert.Equal(fileText, myString); }
public void ReadFromStream_FileStreamWithWhiteSpaces_StringIsFilledWithWhiteSpaces() { // Arrange const string filePath = "temp.txt"; const string fileText = " "; File.WriteAllText(filePath, fileText); var myString = new MyString.MyString("Hello"); // Act using (var fsa = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { myString.ReadFromStream(fsa); } File.Delete(filePath); // Assert Assert.Equal(fileText.Length, myString.Length); Assert.Equal(fileText, myString); }