-
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
Showing
51 changed files
with
863 additions
and
180 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
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
74 changes: 74 additions & 0 deletions
74
ImageMagitek.UnitTests/ExtensionMethodTests/StreamWriteExtensionTestCases.cs
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,74 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ImageMagitek.UnitTests.ExtensionMethodTests | ||
{ | ||
public class StreamWriteExtensionTestCases | ||
{ | ||
public static byte[] singleArray = new byte[] { 0b10011101 }; | ||
public static byte[] largeArray = new byte[] { 0b10110011, 0b11111111, 0b01010101, 0b11001100, 0b10000001 }; | ||
|
||
public static IEnumerable<TestCaseData> WriteUnshiftedCases | ||
{ | ||
get | ||
{ | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 0), 1, | ||
new byte[] { 0b00000000 }, new byte[] { 0b00011101 }); | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 2), 2, | ||
new byte[] { 0b00110000 }, new byte[] { 0b10111101 }); | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 2), 6, | ||
new byte[] { 0b00111110 }, new byte[] { 0b10111110 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(1, 3), 14, | ||
new byte[] { 0b00010101, 0b11010100, 0b00000000 }, new byte[] { 0b10110011, 0b11110101, 0b11010100, 0b01001100, 0b10000001 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(0, 1), 38, | ||
new byte[] { 0b00010101, 0b11010100, 0b01111111, 0b01010100, 0b01101010 }, new byte[] { 0b10010101, 0b11010100, 0b01111111, 0b01010100, 0b01101011 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(0, 0), 40, | ||
new byte[] { 0b00010101, 0b11010100, 0b01111111, 0b01010100, 0b01101010 }, new byte[] { 0b00010101, 0b11010100, 0b01111111, 0b01010100, 0b01101010 }); | ||
|
||
// Cases with unmasked bits outside of writing range | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 0), 1, | ||
new byte[] { 0b00000010 }, new byte[] { 0b00011101 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(1, 3), 14, | ||
new byte[] { 0b00010101, 0b11010100, 0b01111111 }, new byte[] { 0b10110011, 0b11110101, 0b11010100, 0b01001100, 0b10000001 }); | ||
} | ||
} | ||
|
||
//public static byte[] singleArray = new byte[] { 0b10011101 }; | ||
//public static byte[] largeArray = new byte[] { 0b10110011, 0b11111111, 0b01010101, 0b11001100, 0b10000001 }; | ||
|
||
public static IEnumerable<TestCaseData> WriteShiftedCases | ||
{ | ||
get | ||
{ | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 0), 1, | ||
new byte[] { 0b00000000 }, new byte[] { 0b00011101 }); | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 2), 2, | ||
new byte[] { 0b11000000 }, new byte[] { 0b10111101 }); | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 2), 6, | ||
new byte[] { 0b11111000 }, new byte[] { 0b10111110 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(1, 3), 14, | ||
new byte[] { 0b10101110, 0b10100000, 0b00000000 }, new byte[] { 0b10110011, 0b11110101, 0b11010100, 0b01001100, 0b10000001 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(0, 1), 38, | ||
new byte[] { 0b00101011, 0b10101000, 0b11111110, 0b10101000, 0b11010100 }, new byte[] { 0b10010101, 0b11010100, 0b01111111, 0b01010100, 0b01101011 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(0, 0), 40, | ||
new byte[] { 0b00010101, 0b11010100, 0b01111111, 0b01010100, 0b01101010 }, new byte[] { 0b00010101, 0b11010100, 0b01111111, 0b01010100, 0b01101010 }); | ||
|
||
// Cases with unmasked bits outside of writing range | ||
yield return new TestCaseData(singleArray.Clone(), new FileBitAddress(0, 0), 1, | ||
new byte[] { 0b00000010 }, new byte[] { 0b00011101 }); | ||
|
||
yield return new TestCaseData(largeArray.Clone(), new FileBitAddress(1, 3), 14, | ||
new byte[] { 0b10101110, 0b10100011, 0b11111000 }, new byte[] { 0b10110011, 0b11110101, 0b11010100, 0b01001100, 0b10000001 }); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
ImageMagitek.UnitTests/ExtensionMethodTests/StreamWriteExtensionTests.cs
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,36 @@ | ||
using NUnit.Framework; | ||
using System.IO; | ||
using ImageMagitek.ExtensionMethods; | ||
|
||
namespace ImageMagitek.UnitTests.ExtensionMethodTests | ||
{ | ||
[TestFixture] | ||
public class StreamWriteExtensionTests | ||
{ | ||
[TestCaseSource(typeof(StreamWriteExtensionTestCases), "WriteUnshiftedCases")] | ||
public void WriteUnshifted_AsExpected(byte[] data, FileBitAddress offset, int numBits, byte[] writeData, byte[] expected) | ||
{ | ||
using var stream = new MemoryStream(data); | ||
stream.WriteUnshifted(offset, numBits, writeData); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var actual = new byte[expected.Length]; | ||
stream.Read(actual); | ||
|
||
CollectionAssert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestCaseSource(typeof(StreamWriteExtensionTestCases), "WriteShiftedCases")] | ||
public void WriteShifted_AsExpected(byte[] data, FileBitAddress offset, int numBits, byte[] writeData, byte[] expected) | ||
{ | ||
using var stream = new MemoryStream(data); | ||
stream.WriteShifted(offset, numBits, writeData); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var actual = new byte[expected.Length]; | ||
stream.Read(actual); | ||
|
||
CollectionAssert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.