Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump NUnit from 3.14.0 to 4.0.1 #91

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Target .Net 8.0
- Enable AOT and Trim support

## [1.1.0] - 2023-05-15

- Target .Net 6.0 only
Expand Down
3 changes: 3 additions & 0 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Reflection;
using System.Resources;

[assembly: NeutralResourcesLanguage("en-GB")]

[assembly: AssemblyCompany("Health Informatics Centre, University of Dundee")]
[assembly: AssemblyProduct("TypeGuesser")]
Expand Down
15 changes: 9 additions & 6 deletions Tests/BigIntGuessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@

namespace Tests;

internal class BigIntGuessTests
internal sealed class BigIntGuessTests
{
[Test]
public void BigInt_TypeDeciderFactory()
{
var factory = new TypeDeciderFactory(new CultureInfo("en-US"));

// The IDecideTypesForStrings for long should be DecimalTypeDecider
Assert.IsTrue(factory.Dictionary[typeof(long)] is DecimalTypeDecider);
Assert.That(factory.Dictionary[typeof(long)] is DecimalTypeDecider, Is.True);
}

[Test]
public void BigInt_Parse()
{
var decider = new DecimalTypeDecider(new CultureInfo("en-US"));

Assert.AreEqual(100,decider.Parse("100"));
Assert.AreEqual(9223372036854775807L,decider.Parse("9223372036854775807"));

Assert.Multiple(() =>
{
Assert.That(decider.Parse("100"), Is.EqualTo(100));
Assert.That(decider.Parse("9223372036854775807"), Is.EqualTo(9223372036854775807L));
});

}


Expand Down
10 changes: 6 additions & 4 deletions Tests/DatabaseTypeRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@

namespace Tests;

internal class DatabaseTypeRequestTests
internal sealed class DatabaseTypeRequestTests
{
[Test]
public void Test_Max_WithUnicode()
{

var max = DatabaseTypeRequest.Max(
new DatabaseTypeRequest(typeof(string), 1){Unicode = true},
new DatabaseTypeRequest(typeof(string), 2)
);

Assert.AreEqual(2,max.Width);
Assert.IsTrue(max.Unicode,"If either arg in a Max call is Unicode then the resulting maximum should be Unicode=true");
Assert.Multiple(() =>
{
Assert.That(max.Width, Is.EqualTo(2));
Assert.That(max.Unicode, Is.True, "If either arg in a Max call is Unicode then the resulting maximum should be Unicode=true");
});
}
}
106 changes: 68 additions & 38 deletions Tests/DecimalSizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,50 @@

namespace Tests;

internal class DecimalSizeTests
internal sealed class DecimalSizeTests
{
[Test]
public void Test_DecimalSize_Empty()
{
var empty = new DecimalSize();

Assert.AreEqual(0,empty.NumbersAfterDecimalPlace);
Assert.AreEqual(0,empty.NumbersBeforeDecimalPlace);

Assert.AreEqual(0,empty.Precision);
Assert.AreEqual(0,empty.Scale);

Assert.IsTrue(empty.IsEmpty);

Assert.Multiple(() =>
{
Assert.That(empty.NumbersAfterDecimalPlace, Is.EqualTo(0));
Assert.That(empty.NumbersBeforeDecimalPlace, Is.EqualTo(0));

Assert.That(empty.Precision, Is.EqualTo(0));
Assert.That(empty.Scale, Is.EqualTo(0));
});

Assert.That(empty.IsEmpty, Is.True);
}


[Test]
public void Test_DecimalSize_Equality()
{
Assert.AreEqual(new DecimalSize(),new DecimalSize());
Assert.AreEqual(new DecimalSize(),new DecimalSize {NumbersAfterDecimalPlace = 0 });
Assert.AreEqual(new DecimalSize(),new DecimalSize {NumbersAfterDecimalPlace = 0 ,NumbersBeforeDecimalPlace = 0});
Assert.AreEqual(new DecimalSize(3,4),new DecimalSize(3,4));

Assert.AreEqual(new DecimalSize().GetHashCode(),new DecimalSize().GetHashCode());
Assert.AreEqual(new DecimalSize().GetHashCode(),new DecimalSize {NumbersAfterDecimalPlace = 0 }.GetHashCode());
Assert.AreEqual(new DecimalSize().GetHashCode(),new DecimalSize {NumbersAfterDecimalPlace = 0 ,NumbersBeforeDecimalPlace = 0}.GetHashCode());
Assert.AreEqual(new DecimalSize(3,4).GetHashCode(),new DecimalSize {NumbersAfterDecimalPlace = 4 ,NumbersBeforeDecimalPlace = 3}.GetHashCode());
Assert.Multiple(static () =>
{
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(new DecimalSize(), Is.EqualTo(new DecimalSize()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(new DecimalSize { NumbersAfterDecimalPlace = 0 }, Is.EqualTo(new DecimalSize()));
Assert.That(new DecimalSize { NumbersAfterDecimalPlace = 0, NumbersBeforeDecimalPlace = 0 }, Is.EqualTo(new DecimalSize()));
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument - testing for consistency
Assert.That(new DecimalSize(3, 4), Is.EqualTo(new DecimalSize(3, 4)));
});
Assert.Multiple(static () =>
{
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument

#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument - tests for consistency
Assert.That(new DecimalSize().GetHashCode(), Is.EqualTo(new DecimalSize().GetHashCode()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(new DecimalSize { NumbersAfterDecimalPlace = 0 }.GetHashCode(), Is.EqualTo(new DecimalSize().GetHashCode()));
Assert.That(new DecimalSize { NumbersAfterDecimalPlace = 0, NumbersBeforeDecimalPlace = 0 }.GetHashCode(), Is.EqualTo(new DecimalSize().GetHashCode()));
Assert.That(new DecimalSize { NumbersAfterDecimalPlace = 4, NumbersBeforeDecimalPlace = 3 }.GetHashCode(), Is.EqualTo(new DecimalSize(3, 4).GetHashCode()));
});
}

[Test]
Expand All @@ -40,45 +55,60 @@ public void Test_DecimalSize_NoFraction()
//decimal(5,0)
var size = new DecimalSize(5,0);

Assert.AreEqual(5,size.Precision);
Assert.AreEqual(0,size.Scale);

Assert.IsFalse(size.IsEmpty);
Assert.Multiple(() =>
{
Assert.That(size.Precision, Is.EqualTo(5));
Assert.That(size.Scale, Is.EqualTo(0));
});

Assert.That(size.IsEmpty, Is.False);
}
[Test]
public void Test_DecimalSize_SomeFraction()
{
//decimal(7,2)
var size = new DecimalSize(5,2);

Assert.AreEqual(7,size.Precision);
Assert.AreEqual(2,size.Scale);

Assert.IsFalse(size.IsEmpty);
Assert.Multiple(() =>
{
Assert.That(size.Precision, Is.EqualTo(7));
Assert.That(size.Scale, Is.EqualTo(2));
});

Assert.That(size.IsEmpty, Is.False);
}


[Test]
public void Test_DecimalSize_Combine()
{
//decimal(3,0)
var size1 = new DecimalSize(3,0);
Assert.AreEqual(3,size1.Precision);
Assert.AreEqual(0,size1.Scale);
Assert.Multiple(() =>
{
Assert.That(size1.Precision, Is.EqualTo(3));
Assert.That(size1.Scale, Is.EqualTo(0));
});

//decimal(5,4)
var size2 = new DecimalSize(1,4);
Assert.AreEqual(5,size2.Precision);
Assert.AreEqual(4,size2.Scale);
Assert.Multiple(() =>
{
Assert.That(size2.Precision, Is.EqualTo(5));
Assert.That(size2.Scale, Is.EqualTo(4));
});


var combined = DecimalSize.Combine(size1,size2);

Assert.AreEqual(3,combined.NumbersBeforeDecimalPlace);
Assert.AreEqual(4,combined.NumbersAfterDecimalPlace);

//decimal(7,4)
Assert.AreEqual(7,combined.Precision);
Assert.AreEqual(4,combined.Scale);
Assert.Multiple(() =>
{
Assert.That(combined.NumbersBeforeDecimalPlace, Is.EqualTo(3));
Assert.That(combined.NumbersAfterDecimalPlace, Is.EqualTo(4));

//decimal(7,4)
Assert.That(combined.Precision, Is.EqualTo(7));
Assert.That(combined.Scale, Is.EqualTo(4));
});
}
}
71 changes: 43 additions & 28 deletions Tests/GuessSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Tests;

internal class GuessSettingsTests
internal sealed class GuessSettingsTests
{
[TestCase("Y")]
[TestCase("N")]
Expand All @@ -15,17 +15,23 @@ internal class GuessSettingsTests
public void Guess_TF_Settings(string candidate)
{
//default is true
Assert.IsTrue(GuessSettingsFactory.Defaults.CharCanBeBoolean);
Assert.That(GuessSettingsFactory.Defaults.CharCanBeBoolean, Is.True);

var decider = new BoolTypeDecider(CultureInfo.CurrentCulture);

//T = True
Assert.IsTrue(decider.IsAcceptableAsType(candidate,null));
Assert.IsTrue(decider.IsAcceptableAsType("1",null));

Assert.Multiple(() =>
{
//T = True
Assert.That(decider.IsAcceptableAsType(candidate, null), Is.True);
Assert.That(decider.IsAcceptableAsType("1", null), Is.True);
});

decider.Settings.CharCanBeBoolean = false;
Assert.IsFalse(decider.IsAcceptableAsType(candidate,null));
Assert.IsTrue(decider.IsAcceptableAsType("1",null)); //setting does not affect 1/0
Assert.Multiple(() =>
{
Assert.That(decider.IsAcceptableAsType(candidate, null), Is.False);
Assert.That(decider.IsAcceptableAsType("1", null), Is.True); //setting does not affect 1/0
});
}

[Test]
Expand All @@ -34,32 +40,38 @@ public void Guess_TF_Factory()
const string candidate = "T";

//default is true
Assert.IsTrue(GuessSettingsFactory.Defaults.CharCanBeBoolean);
Assert.That(GuessSettingsFactory.Defaults.CharCanBeBoolean, Is.True);

var factory = new TypeDeciderFactory(CultureInfo.CurrentCulture);
var deciderOld = factory.Create(typeof(bool));

//T = True
Assert.IsTrue(deciderOld.IsAcceptableAsType(candidate,null));
Assert.IsTrue(deciderOld.IsAcceptableAsType("1",null));

Assert.Multiple(() =>
{
//T = True
Assert.That(deciderOld.IsAcceptableAsType(candidate, null), Is.True);
Assert.That(deciderOld.IsAcceptableAsType("1", null), Is.True);
});

factory.Settings.CharCanBeBoolean = false;
var deciderNew = factory.Create(typeof(bool));

Assert.IsFalse(ReferenceEquals(deciderOld,deciderNew), "Factory Create created a reference to the same old instance! not a fresh one");
Assert.IsTrue(deciderOld.Settings.CharCanBeBoolean);
Assert.IsFalse(deciderNew.Settings.CharCanBeBoolean);
Assert.Multiple(() =>
{
Assert.That(ReferenceEquals(deciderOld, deciderNew), Is.False, "Factory Create created a reference to the same old instance! not a fresh one");
Assert.That(deciderOld.Settings.CharCanBeBoolean, Is.True);
Assert.That(deciderNew.Settings.CharCanBeBoolean, Is.False);

Assert.IsFalse(deciderNew.IsAcceptableAsType(candidate,null));
Assert.IsTrue(deciderNew.IsAcceptableAsType("1",null)); //setting does not affect 1/0
Assert.That(deciderNew.IsAcceptableAsType(candidate, null), Is.False);
Assert.That(deciderNew.IsAcceptableAsType("1", null), Is.True); //setting does not affect 1/0
});
}
[Test]
public void Guess_TF_Guesser()
{
const string candidate = "T";

//default is true
Assert.IsTrue(GuessSettingsFactory.Defaults.CharCanBeBoolean);
Assert.That(GuessSettingsFactory.Defaults.CharCanBeBoolean, Is.True);

//start with a guesser
var guesser = new Guesser();
Expand All @@ -68,38 +80,41 @@ public void Guess_TF_Guesser()
guesser.AdjustToCompensateForValue(candidate);

//so bool should be the guess for "Y"
Assert.AreEqual(typeof(bool),guesser.Guess.CSharpType);
Assert.That(guesser.Guess.CSharpType, Is.EqualTo(typeof(bool)));

//change the guesser settings so "Y" is no longer acceptable as bool
guesser.Settings.CharCanBeBoolean = false;
Assert.AreEqual(typeof(bool),guesser.Guess.CSharpType); //guess is only re evaluated on calls to Adjust
Assert.That(guesser.Guess.CSharpType, Is.EqualTo(typeof(bool))); //guess is only re evaluated on calls to Adjust

//Guess again!
guesser.AdjustToCompensateForValue(candidate);
Assert.AreEqual(typeof(string),guesser.Guess.CSharpType,"Guess should be string after the next evaluation");
Assert.That(guesser.Guess.CSharpType, Is.EqualTo(typeof(string)), "Guess should be string after the next evaluation");

}

[Test]
public void Test_GuessSettingsFactory_Defaults()
{
//default is true
Assert.IsTrue(GuessSettingsFactory.Defaults.CharCanBeBoolean);
Assert.That(GuessSettingsFactory.Defaults.CharCanBeBoolean, Is.True);
var instance = GuessSettingsFactory.Create();
Assert.IsTrue(instance.CharCanBeBoolean);
Assert.Multiple(() =>
{
Assert.That(instance.CharCanBeBoolean, Is.True);

Assert.IsFalse(instance == GuessSettingsFactory.Defaults);
Assert.That(instance, Is.Not.SameAs(GuessSettingsFactory.Defaults));
});

//changing static defaults
GuessSettingsFactory.Defaults.CharCanBeBoolean = false;

try
{
//should change the result of Create to the new default
Assert.IsFalse(GuessSettingsFactory.Create().CharCanBeBoolean);
Assert.That(GuessSettingsFactory.Create().CharCanBeBoolean, Is.False);

var decider = new DecimalTypeDecider(CultureInfo.CurrentCulture);
Assert.IsFalse(decider.Settings.CharCanBeBoolean);
Assert.That(decider.Settings.CharCanBeBoolean, Is.False);
}
finally
{
Expand Down
Loading