Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Extend tests on appending.

implement ISet and update namespace.
  • Loading branch information
Corniel committed Feb 15, 2024
1 parent b3d404c commit 254cd4b
Show file tree
Hide file tree
Showing 13 changed files with 1,020 additions and 672 deletions.
21 changes: 21 additions & 0 deletions specs/Qowaiv.Specs/Collections/Email_address_collection_specs.cs
@@ -0,0 +1,21 @@
//#if NET8_0_OR_GREATER
//#else
//namespace Email_address_collection_specs;

//public class Supports_binary_serialization
//{
// [Test]
// [Obsolete("Usage of the binary formatter is considered harmful.")]
// public void using_BinaryFormatter()
// {
// var round_tripped = SerializeDeserialize.Binary(Svo.EmailAddressCollection);
// round_tripped.Should().BeEquivalentTo(Svo.EmailAddressCollection);
// }
// [Test]
// public void storing_string_in_SerializationInfo()
// {
// var info = Serialize.GetInfo(Svo.EmailAddressCollection);
// info.GetString("Value").Should().Be("info@qowaiv.org,test@qowaiv.org");
// }
//}
//#endif
111 changes: 111 additions & 0 deletions specs/Qowaiv.Specs/Collections/Email_address_set_specs.cs
@@ -0,0 +1,111 @@
using Qowaiv.Collections;

namespace Collections.Email_address_set_specs;

public class Appends
{
[Test]
public void new_email_address_in_ascending_order([Range(0, 25)] int index)
{
var emails = Enumerable.Range(0, 26).Select(i => EmailAddress.Parse($"{(char)('A' + i)}@qowaiv.org")).ToArray();
var collection = EmailAddressCollection.New(emails);

IReadOnlyCollection<EmailAddress> appended = collection.Append(EmailAddress.Parse($"{emails[index]}.com"));

appended.Should().HaveCount(collection.Count + 1);
appended.Should().BeInAscendingOrder();
}

[Test]
public void existing_email_address_changes_nothing([Range(0, 25)] int index)
{
var emails = Enumerable.Range(0, 26).Select(i => EmailAddress.Parse($"{(char)('A' + i)}@qowaiv.org")).ToArray();
var collection = EmailAddressCollection.New(emails);

object appended = collection.Append(emails[index]);
appended.Should().Be(collection);
}

[TestCase("")]
[TestCase("?")]
public void changes_nothing_for_empty_or_unknown(EmailAddress notKnown)
{
object appended = Svo.EmailAddressCollection.Append(notKnown);
appended.Should().Be(Svo.EmailAddressCollection);
}
}

public class Implements_ISet
{
private readonly EmailAddressCollection empty = EmailAddressCollection.Empty;
private readonly EmailAddressCollection set = Svo.EmailAddressCollection;
private readonly EmailAddressCollection more = Svo.EmailAddressCollection.Append(EmailAddress.Parse("jimmy@hendrix.com"));
private readonly EmailAddressCollection less = EmailAddressCollection.New(Svo.EmailAddressCollection.Skip(1));
private readonly EmailAddressCollection other = EmailAddressCollection.New(Svo.EmailAddressCollection.Skip(1).Concat([EmailAddress.Parse("jimmy@hendrix.com")]));
private readonly EmailAddressCollection different = EmailAddressCollection.New([EmailAddress.Parse("jimmy@hendrix.com"), EmailAddress.Parse("nick@drake.co.uk")]);

[Test]
public void Is_subset()
{
empty.IsSubsetOf(empty).Should().Be(empty.ToHashSet().IsSubsetOf(empty));
empty.IsSubsetOf(set).Should().Be(empty.ToHashSet().IsSubsetOf(set));

set.IsSubsetOf(set).Should().Be(set.ToHashSet().IsSubsetOf(set));
set.IsSubsetOf(more).Should().Be(set.ToHashSet().IsSubsetOf(more));
set.IsSubsetOf(less).Should().Be(set.ToHashSet().IsSubsetOf(less));
set.IsSubsetOf(other).Should().Be(set.ToHashSet().IsSubsetOf(other));
set.IsSubsetOf(different).Should().Be(set.ToHashSet().IsSubsetOf(different));
}

[Test]
public void Is_proper_subset()
{
empty.IsProperSubsetOf(empty).Should().Be(empty.ToHashSet().IsProperSubsetOf(empty));
empty.IsProperSubsetOf(set).Should().Be(empty.ToHashSet().IsProperSubsetOf(set));

set.IsProperSubsetOf(set).Should().Be(set.ToHashSet().IsProperSubsetOf(set));
set.IsProperSubsetOf(more).Should().Be(set.ToHashSet().IsProperSubsetOf(more));
set.IsProperSubsetOf(less).Should().Be(set.ToHashSet().IsProperSubsetOf(less));
set.IsProperSubsetOf(other).Should().Be(set.ToHashSet().IsProperSubsetOf(other));
set.IsProperSubsetOf(different).Should().Be(set.ToHashSet().IsProperSubsetOf(different));
}

[Test]
public void Is_superset()
{
empty.IsSupersetOf(empty).Should().Be(empty.ToHashSet().IsSupersetOf(empty));
empty.IsSupersetOf(set).Should().Be(empty.ToHashSet().IsSupersetOf(set));

set.IsSupersetOf(set).Should().Be(set.ToHashSet().IsSupersetOf(set));
set.IsSupersetOf(more).Should().Be(set.ToHashSet().IsSupersetOf(more));
set.IsSupersetOf(less).Should().Be(set.ToHashSet().IsSupersetOf(less));
set.IsSupersetOf(other).Should().Be(set.ToHashSet().IsSupersetOf(other));
set.IsSupersetOf(different).Should().Be(set.ToHashSet().IsSupersetOf(different));
}

[Test]
public void Is_proper_superset()
{
empty.IsProperSupersetOf(empty).Should().Be(empty.ToHashSet().IsProperSupersetOf(empty));
empty.IsProperSupersetOf(set).Should().Be(empty.ToHashSet().IsProperSupersetOf(set));

set.IsProperSupersetOf(set).Should().Be(set.ToHashSet().IsProperSupersetOf(set));
set.IsProperSupersetOf(more).Should().Be(set.ToHashSet().IsProperSupersetOf(more));
set.IsProperSupersetOf(less).Should().Be(set.ToHashSet().IsProperSupersetOf(less));
set.IsProperSupersetOf(other).Should().Be(set.ToHashSet().IsProperSupersetOf(other));
set.IsProperSupersetOf(different).Should().Be(set.ToHashSet().IsProperSupersetOf(different));
}

[Test]
public void Overlaps()
{
empty.Overlaps(empty).Should().Be(empty.ToHashSet().Overlaps(empty));
empty.Overlaps(set).Should().Be(empty.ToHashSet().Overlaps(set));

set.Overlaps(set).Should().Be(set.ToHashSet().Overlaps(set));
set.Overlaps(more).Should().Be(set.ToHashSet().Overlaps(more));
set.Overlaps(less).Should().Be(set.ToHashSet().Overlaps(less));
set.Overlaps(other).Should().Be(set.ToHashSet().Overlaps(other));
set.Overlaps(different).Should().Be(set.ToHashSet().Overlaps(different));
}
}
21 changes: 0 additions & 21 deletions specs/Qowaiv.Specs/Email_address_collection_specs.cs

This file was deleted.

3 changes: 2 additions & 1 deletion specs/Qowaiv.Specs/TestTools/Svo.cs
@@ -1,4 +1,5 @@
using Qowaiv.Chemistry;
using Qowaiv.Collections;
using Qowaiv.Customization;
using Qowaiv.Sustainability;

Expand Down Expand Up @@ -44,7 +45,7 @@ public static class Svo
public static readonly EmailAddress EmailAddress = EmailAddress.Parse("info@qowaiv.org");

/// <summary>info@qowaiv.org,test@qowaiv.org"</summary>
public static EmailAddressCollection EmailAddressCollection => EmailAddressCollection.Parse("info@qowaiv.org,test@qowaiv.org");
public static EmailAddressCollection EmailAddressCollection => EmailAddressCollection.New(["info@qowaiv.org", "test@qowaiv.org"]);

/// <summary>1732.4</summary>
public static readonly Elo Elo = 1732.4;
Expand Down

0 comments on commit 254cd4b

Please sign in to comment.