Skip to content

Commit

Permalink
Fix fifoset (3x) (#905)
Browse files Browse the repository at this point in the history
* Fix fifo set

* More tests for FIFO size

* Fixing indexes

* Testing asset of different sets

* Testing again

* Update UT_FifoSet.cs

* Update UT_FifoSet.cs

* Tests for fifo max size

* Fixing indentation
  • Loading branch information
shargon committed Jul 10, 2019
1 parent 54e772a commit 1d949c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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();
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

0 comments on commit 1d949c8

Please sign in to comment.