forked from Jofairden/EvenMoreModifiers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitTests.cs
112 lines (90 loc) · 3.54 KB
/
UnitTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Linq;
using System.Reflection;
using Loot.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Terraria.ModLoader.IO;
namespace Loot
{
// @ TODO problem (bug), cannot compile from VS, does not care about buildIgnore
//public class EmptyModLoadShell : Mod
//{
//}
[TestClass]
public class UnitTest
{
//private EmptyModLoadShell modShell;
[TestMethod]
public void TestModifierProperties()
{
//Assert.AreEqual(new ModifierProperties(), new ModifierProperties());
var p = new ModifierProperties();
Assert.AreEqual(p.Magnitude, 0f);
Assert.AreEqual(p.Power, 0f);
Assert.AreEqual(p.RoundedPower, 0f);
float n = 10f, m = n * 2f;
p = new ModifierProperties(minMagnitude: n, maxMagnitude: m);
Assert.AreEqual(p.MinMagnitude, n);
Assert.AreEqual(p.MaxMagnitude, m);
Assert.AreEqual(p.MinMagnitude, p.MaxMagnitude - n);
Assert.AreEqual(p.MaxMagnitude, p.MinMagnitude + n);
Assert.IsTrue(p.MinMagnitude <= p.MaxMagnitude);
Assert.IsTrue(p.MaxMagnitude >= p.MinMagnitude);
p = p.RollMagnitudeAndPower(10f, 100f);
var tc = ModifierProperties._Save(null, p);
Assert.IsInstanceOfType(tc, typeof(TagCompound));
Assert.IsTrue(tc.ContainsKey("Magnitude"));
Assert.IsTrue(tc.ContainsKey("Power"));
Assert.IsTrue(tc.ContainsKey("ModifierPropertiesSaveVersion"));
Assert.AreEqual(tc.Get<float>("Magnitude"), 10f);
Assert.AreEqual(tc.Get<float>("Power"), 100f);
Assert.IsTrue(tc.Get<int>("ModifierPropertiesSaveVersion") > 0);
p = ModifierProperties._Load(null, tc);
Assert.IsInstanceOfType(p, typeof(ModifierProperties));
Assert.AreEqual(p.Magnitude, 10f);
Assert.AreEqual(p.Magnitude, tc.Get<float>("Magnitude"));
Assert.AreEqual(p.Power, 100f);
Assert.AreEqual(p.Power, tc.Get<float>("Power"));
}
[TestMethod]
public void TestEMMLoader()
{
//modShell = new EmptyModLoadShell();
EMMLoader.Initialize();
EMMLoader.Load();
Assert.IsTrue(EMMLoader.ReserveRarityID() == 0);
Assert.IsTrue(EMMLoader.ReserveModifierID() == 0);
Assert.IsTrue(EMMLoader.ReservePoolID() == 0);
Assert.IsTrue(EMMLoader.RaritiesMap.Count == 0);
Assert.IsTrue(EMMLoader.ModifiersMap.Count == 0);
Assert.IsTrue(EMMLoader.PoolsMap.Count == 0);
Assert.IsTrue(EMMLoader.GlobalModifiersMap.Count == 0);
Assert.IsTrue(EMMLoader.Rarities.Count == 0);
Assert.IsTrue(EMMLoader.Modifiers.Count == 0);
Assert.IsTrue(EMMLoader.Pools.Count == 0);
Assert.IsTrue(EMMLoader.GlobalModifiers.Count == 0);
Assert.IsTrue(EMMLoader.Mods.Count == 0);
//Assert.ThrowsException<Exception>(() => EMMLoader.RegisterMod(modShell));
//var f = modShell.GetType().GetField("loading", BindingFlags.Instance | BindingFlags.NonPublic);
//f.SetValue(modShell, true);
//EMMLoader.RegisterMod(modShell);
//Assert.ThrowsException<Exception>(() => EMMLoader.RegisterMod(modShell));
//Assert.IsTrue(EMMLoader.Mods.Count == 1);
//Assert.IsTrue(EMMLoader.RaritiesMap.Count == 1);
//Assert.IsTrue(EMMLoader.ModifiersMap.Count == 1);
//Assert.IsTrue(EMMLoader.PoolsMap.Count == 1);
//Assert.IsTrue(EMMLoader.GlobalModifiersMap.Count == 1);
}
[TestMethod]
public void LogModifiers()
{
var mod = new Loot();
var f = mod.GetType().GetField("loading", BindingFlags.Instance | BindingFlags.NonPublic);
f.SetValue(mod, true);
mod.Load();
f.SetValue(mod, false);
Console.Write(string.Join("\n", EMMLoader.RequestModifierRarities().Select(x => x.Name)));
Console.Write(string.Join("\n", EMMLoader.RequestModifiers().Select(x => x.TooltipLines)));
}
}
}