From aa7d6028ee62f928effab617c0ca4a0c800b39d0 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 9 Jul 2019 19:43:41 +0200 Subject: [PATCH 1/9] Fix fifo set --- neo.UnitTests/UT_FifoSet.cs | 32 ++++++++++++++++++++++++++++++++ neo/IO/Caching/FIFOSet.cs | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 neo.UnitTests/UT_FifoSet.cs diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs new file mode 100644 index 0000000000..3876661af3 --- /dev/null +++ b/neo.UnitTests/UT_FifoSet.cs @@ -0,0 +1,32 @@ +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(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 }); + } + } +} \ No newline at end of file diff --git a/neo/IO/Caching/FIFOSet.cs b/neo/IO/Caching/FIFOSet.cs index 6dd52dbccf..7769cb5ad5 100644 --- a/neo/IO/Caching/FIFOSet.cs +++ b/neo/IO/Caching/FIFOSet.cs @@ -51,7 +51,7 @@ public void ExceptWith(IEnumerable hashes) public IEnumerator GetEnumerator() { - var entries = dictionary.Values.Cast().ToArray(); + var entries = dictionary.Keys.Cast().ToArray(); foreach (var entry in entries) yield return entry; } From 5547a8e2fbdd27b8baea0a25713ad262d1d8246b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Tue, 9 Jul 2019 15:33:33 -0300 Subject: [PATCH 2/9] More tests for FIFO size --- neo.UnitTests/UT_FifoSet.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 3876661af3..05e5b078d5 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -27,6 +27,26 @@ public void FifoSetTest() 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 + }); + + Assert.IsTrue(set.Add(d)); + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, b, 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)); + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, d, e }); } } -} \ No newline at end of file +} From 3572c9eb5ee77b14eb3d770724a8384e448a8bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Tue, 9 Jul 2019 15:34:49 -0300 Subject: [PATCH 3/9] Fixing indexes --- neo.UnitTests/UT_FifoSet.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 05e5b078d5..5442b08ea2 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -36,7 +36,7 @@ public void FifoSetTest() }); Assert.IsTrue(set.Add(d)); - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, b, 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, @@ -46,7 +46,7 @@ public void FifoSetTest() }); Assert.IsTrue(set.Add(e)); - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, d, e }); + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e }); } } } From 933f09a68b8226599eebfd330f385bfa0b877c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Tue, 9 Jul 2019 19:37:42 -0300 Subject: [PATCH 4/9] Testing asset of different sets --- neo.UnitTests/UT_FifoSet.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 5442b08ea2..1057007115 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -47,6 +47,11 @@ public void FifoSetTest() Assert.IsTrue(set.Add(e)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e }); + + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, d, e }); + + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, b, e }); + } } } From e62d78e940753fb736fd5680ec86ad07fa6b0acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Tue, 9 Jul 2019 20:19:57 -0300 Subject: [PATCH 5/9] Testing again --- neo.UnitTests/UT_FifoSet.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 1057007115..4cfdd2d47f 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -48,6 +48,10 @@ public void FifoSetTest() Assert.IsTrue(set.Add(e)); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e }); + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, e, d }); + + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, b, e }); + CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, d, e }); CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, b, e }); From 4a239e06bc9bb7ba75a249b755cf65520c14514d Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 10 Jul 2019 07:12:01 +0200 Subject: [PATCH 6/9] Update UT_FifoSet.cs --- neo.UnitTests/UT_FifoSet.cs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 4cfdd2d47f..b24e1b99ac 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -27,35 +27,7 @@ public void FifoSetTest() 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 - }); - - 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)); - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e }); - - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, e, d }); - - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, b, e }); - - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, d, e }); - - CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, b, e }); - } } } + From 0ac840cdf48c8403936c1fc27cdd5374503838a9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 10 Jul 2019 07:12:59 +0200 Subject: [PATCH 7/9] Update UT_FifoSet.cs --- neo.UnitTests/UT_FifoSet.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index b24e1b99ac..218aeefde2 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -30,4 +30,3 @@ public void FifoSetTest() } } } - From f2b516f0d4b5afdac34fc0203dfbfffe5355cec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Wed, 10 Jul 2019 14:11:45 -0300 Subject: [PATCH 8/9] Tests for fifo max size --- neo.UnitTests/UT_FifoSet.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index 218aeefde2..f1c611bdfa 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -27,6 +27,28 @@ public void FifoSetTest() 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 }); } } } From b0da5a69e130a97307b9f358e8186f6c3bc1245e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Wed, 10 Jul 2019 15:09:26 -0300 Subject: [PATCH 9/9] Fixing indentation --- neo.UnitTests/UT_FifoSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/UT_FifoSet.cs b/neo.UnitTests/UT_FifoSet.cs index f1c611bdfa..ff5ccf9c27 100644 --- a/neo.UnitTests/UT_FifoSet.cs +++ b/neo.UnitTests/UT_FifoSet.cs @@ -28,7 +28,7 @@ public void FifoSetTest() CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c }); - var d = new UInt256(new byte[32] { + 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,