Commit 2c6cf6da authored by Brickner_cp's avatar Brickner_cp

Code coverage 95.65%

parent 7a662074
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for BitSequenceTest
/// </summary>
[TestClass]
public class BitSequenceTest
{
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void Merge8BoolRandomTest()
{
Random random = new Random();
for (int i = 0; i != 10; ++i)
{
byte expectedResult = 0;
bool[] input = new bool[8];
for (int bit = 0; bit != 8; ++bit)
{
bool bitValue = random.NextBool();
input[bit] = bitValue;
expectedResult <<= 1;
if (bitValue)
++expectedResult;
}
Assert.AreEqual(expectedResult, BitSequence.Merge(input[0], input[1], input[2], input[3], input[4], input[5], input[6], input[7]));
}
}
}
}
\ No newline at end of file
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for DateTimeExtensionsTest
/// </summary>
[TestClass]
public class DateTimeExtensionsTest
{
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void AddMicrosecondsValueTooBigTest()
{
DateTime dateTime = DateTime.Now;
dateTime.AddMicroseconds((long.MaxValue / TimeSpanExtensions.TicksPerMicrosecond) * 2);
Assert.IsNotNull(dateTime);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void AddMicrosecondsValueTooSmallTest()
{
DateTime dateTime = DateTime.Now;
dateTime.AddMicroseconds((long.MinValue / TimeSpanExtensions.TicksPerMicrosecond) * 2);
Assert.IsNotNull(dateTime);
Assert.Fail();
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
......@@ -93,5 +94,21 @@ namespace PcapDotNet.Base.Test
};
Assert.AreEqual(0x87654321L, longValues.Xor());
}
[TestMethod]
public void IsStrictOrderedTest()
{
Assert.IsTrue(new[] {1, 2, 3, 4, 5}.IsStrictOrdered(value => value, Comparer<int>.Default));
Assert.IsFalse(new[] { 1, 2, 3, 3, 5 }.IsStrictOrdered(value => value, Comparer<int>.Default));
Assert.IsFalse(new[] { 1, 2, 3, 4, 3 }.IsStrictOrdered(value => value, Comparer<int>.Default));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IsStrictOrderedNullComparerTest()
{
Assert.IsFalse(new[] { 1, 2, 3, 4, 5 }.IsStrictOrdered(value => value, null));
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -67,6 +67,8 @@
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="BitSequenceTest.cs" />
<Compile Include="DateTimeExtensionsTest.cs" />
<Compile Include="IDictionaryExtensionsTests.cs" />
<Compile Include="FuncExtensionsTest.cs" />
<Compile Include="IEnumerableExtensionsTests.cs" />
......
......@@ -48,7 +48,7 @@ namespace PcapDotNet.Base.Test
{
UInt128 value = random.NextUInt128();
// Test equality
// Test comparisons.
Assert.AreEqual(value, value);
Assert.AreNotEqual(value, string.Empty);
Assert.AreNotEqual(value, UInt128.MaxValue);
......@@ -56,7 +56,16 @@ namespace PcapDotNet.Base.Test
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
Assert.IsTrue(value <= value);
Assert.IsTrue(value >= value);
// ReSharper restore EqualExpressionComparison
if (value != UInt128.MaxValue)
{
Assert.IsTrue(value < value + 1);
Assert.IsTrue(value <= value + 1);
Assert.IsTrue(value + 1 > value);
Assert.IsTrue(value + 1 >= value);
}
// Test GetHashCode
Assert.IsNotNull(value.GetHashCode());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment