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

Fix fifoset (3x) #905

Merged
merged 9 commits into from
Jul 10, 2019
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
54 changes: 54 additions & 0 deletions neo.UnitTests/UT_FifoSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO.Caching;
using System.Linq;

namespace Neo.UnitTests
{
[TestClass]
public class UT_FifoSet
{
[TestMethod]
public void FifoSetTest()
{
var a = UInt256.Zero;
var b = new UInt256();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UInt256.Zero? Better than new UInt256(), no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the same data, with different objects

Copy link
Contributor

@igormcoelho igormcoelho Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use two new UInt256(). Isn't it clearer? Or does it risk being the same object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Is the same

var c = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01
});

var set = new FIFOSet<UInt256>(3);

Assert.IsTrue(set.Add(a));
Assert.IsFalse(set.Add(a));
Assert.IsFalse(set.Add(b));
Assert.IsTrue(set.Add(c));

CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c });

var d = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x02
});

// Testing Fifo max size
Assert.IsTrue(set.Add(d));
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c, d });

var e = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x03
});

Assert.IsTrue(set.Add(e));
Assert.IsFalse(set.Add(e));
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e });
}
}
}
2 changes: 1 addition & 1 deletion neo/IO/Caching/FIFOSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ExceptWith(IEnumerable<UInt256> hashes)

public IEnumerator<T> GetEnumerator()
{
var entries = dictionary.Values.Cast<T>().ToArray();
var entries = dictionary.Keys.Cast<T>().ToArray();
foreach (var entry in entries) yield return entry;
}

Expand Down