Skip to content

Commit

Permalink
Ensuring that is using valid trees for the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Nov 15, 2018
1 parent 34f81f6 commit 2b76e25
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions NeoDataStructureTest/MerklePatriciaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ void InserirTestar(string x, string y)

InserirTestar("01a2", "valor1");
Assert.Equal(1, merklePatricia.Height());
Assert.True(merklePatricia.Validade());

InserirTestar("11a2", "valor2");
Assert.True(merklePatricia.Validade());

InserirTestar("0212", "valor3");
Assert.Equal(3, merklePatricia.Height());
Assert.True(merklePatricia.Validade());

merklePatricia["0"] = "valor4";
Assert.True(merklePatricia.Validade());
}

[Fact]
Expand All @@ -51,28 +55,35 @@ public void ColideKeys()
};
Assert.True(merklePatricia.ContainsKey("oi"));
Assert.Equal("batatatinha", merklePatricia["oi"]);
Assert.True(merklePatricia.Validade());

merklePatricia["orelha"] = "batatatinha";
Assert.Equal("batatatinha", merklePatricia["orelha"]);
Assert.True(merklePatricia.Validade());

merklePatricia["orfão"] = "criança";
Assert.Equal("criança", merklePatricia["orfão"]);
Assert.True(merklePatricia.Validade());

merklePatricia["orfanato"] = "crianças";
Assert.Equal("crianças", merklePatricia["orfanato"]);
Assert.True(merklePatricia.Validade());

merklePatricia.Remove("orfanato");
Assert.Equal("criança", merklePatricia["orfão"]);
Assert.False(merklePatricia.ContainsKey("orfanato"));
Assert.True(merklePatricia.Validade());

merklePatricia["orfã"] = "menina";
Assert.Equal("menina", merklePatricia["orfã"]);
Assert.True(merklePatricia.Validade());
}

[Fact]
public void Remove()
{
var mp = new MerklePatricia();
Assert.True(mp.Validade());

void RemoverTestar(string x, string y)
{
Expand All @@ -87,24 +98,30 @@ void RemoverTestar(string x, string y)
}

RemoverTestar("oi", "bala");
Assert.True(mp.Validade());
mp.Remove("oi");
Assert.False(mp.ContainsKey("oi"));
Assert.True(mp.Validade());

mp["123"] = "abc";
mp["a123"] = "1abc";
Assert.Equal(2, mp.Count());

Assert.True(mp.Validade());

Assert.False(mp.Remove("b123"));
Assert.Equal(2, mp.Count());
Assert.True(mp.Remove("a123"));
// TODO Solve problem on the remove method, not removing from _db
Assert.True(mp.Validade());
Assert.Equal(1, mp.Count());
Assert.False(mp.ContainsKey("a123"));
Assert.True(mp.ContainsKey("123"));
Assert.True(mp.ContainsKey("123"));
Assert.True(mp.Validade());

var mp2 = new MerklePatricia {["123"] = "abc"};
Assert.Equal(mp2, mp);
Assert.True(mp.Validade());
Assert.True(mp2.Validade());
}

[Fact]
Expand All @@ -117,6 +134,7 @@ public void EqualsThree()
["oi2"] = "b2ola",
["oi1"] = "bola1"
};
Assert.True(mpA.Validade());

var mpB = new MerklePatricia
{
Expand All @@ -125,31 +143,38 @@ public void EqualsThree()
["oi2"] = "b2ola",
["oi1"] = "bola1"
};
Assert.True(mpB.Validade());
Assert.Equal(mpA, mpB);

mpA["oi"] = "escola";
Assert.NotEqual(mpA, mpB);
Assert.True(mpA.Validade());

mpB["oi"] = "escola";
Assert.Equal(mpA, mpB);
Assert.True(mpB.Validade());

mpA["oi123"] = "escola";
mpA["oi12"] = "escola1";
mpA["bola"] = "escola2";
mpA["dog"] = "escola2";
Assert.True(mpA.Validade());

mpB["bola"] = "escola2";
mpB["dog"] = "escola2";
mpB["oi12"] = "escola1";
mpB["oi123"] = "escola";
Assert.Equal(mpA, mpB);
Assert.True(mpB.Validade());

mpA.Remove("oi");
mpA.Remove("oi");
Assert.NotEqual(mpA, mpB);
Assert.True(mpA.Validade());

mpB.Remove("oi");
Assert.Equal(mpA, mpB);
Assert.True(mpB.Validade());
}

[Fact]
Expand All @@ -161,6 +186,7 @@ public void Lista()
{
mp[it] = it.CompactEncodeString();
System.Console.WriteLine($"{mp}");
Assert.True(mp.Validade());
}
}

Expand All @@ -184,32 +210,38 @@ public void Dictionary()
{
merklePatricia[keyValue.Key] = keyValue.Value;
}
Assert.True(merklePatricia.Validade());

foreach (var keyValue in exemplo)
{
Assert.Equal(keyValue.Value, merklePatricia[keyValue.Key]);
}
Assert.True(merklePatricia.Validade());
}

[Fact]
public void PatriciaToString()
{
var mp = new MerklePatricia();
Assert.True(mp.Validade());
System.Console.WriteLine($"a:\n {mp}");
mp["oi"] = "bala";
Assert.True(mp.Validade());
System.Console.WriteLine($"a:\n {mp}");
mp["oi1"] = "bala1";
System.Console.WriteLine($"a:\n {mp}");
mp["oi2"] = "bala2";
System.Console.WriteLine($"a:\n {mp}");
mp["oi12"] = "bala12";
Assert.True(mp.Validade());
System.Console.WriteLine($"a:\n {mp}");
mp["bola"] = "123bala12";
System.Console.WriteLine($"a:\n {mp}");
mp["birosca123"] = "13bala12";
System.Console.WriteLine($"a:\n {mp}");
mp["ca123"] = "3bala12";
mp["oi123"] = "asfbala12";
Assert.True(mp.Validade());
System.Console.WriteLine($"a:\n {mp}");
}

Expand All @@ -218,22 +250,26 @@ public void PatriciaCount()
{
var mp = new MerklePatricia();
Assert.Equal(0, mp.Count());

Assert.True(mp.Validade());

mp["oi"] = "oi";
Assert.Equal(1, mp.Count());

Assert.True(mp.Validade());

mp["oi"] = "oi";
Assert.Equal(1, mp.Count());

Assert.True(mp.Validade());

mp["oi"] = "oi1";
Assert.Equal(1, mp.Count());

mp["oi1"] = "oi1";
mp["oi2"] = "oi2";
Assert.Equal(3, mp.Count());

mp["bala"] = "bala2";
Assert.Equal(4, mp.Count());
Assert.True(mp.Validade());
}

[Fact]
Expand All @@ -245,13 +281,15 @@ public void ContainsValue()
["boi2"] = "oi2",
["coi1"] = "oi3"
};
Assert.True(mp.Validade());
Assert.True(mp.ContainsValue("oi"));
Assert.True(mp.ContainsValue("oi2"));
Assert.True(mp.ContainsValue("oi3"));

Assert.False(mp.ContainsValue("aoi"));
Assert.False(mp.ContainsValue("boi2"));
Assert.False(mp.ContainsValue("coi3"));
Assert.True(mp.Validade());
}
}
}

0 comments on commit 2b76e25

Please sign in to comment.