-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPurchaseGeneratorTests.m
92 lines (84 loc) · 3.37 KB
/
PurchaseGeneratorTests.m
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
classdef PurchaseGeneratorTests < matlab.unittest.TestCase
methods (Test)
function testRWGInitialization(TestCase)
T_a = Token("TokenA");
T_b = Token("TokenB");
Q_a = 100000;
Q_b = 10000;
pool = LiquidityPool(T_a, T_b, Q_a, Q_b);
n = 100000;
initialTaPrice = 1;
initialCapitalization = Q_a*initialTaPrice;
maxAvailability = Q_a*initialTaPrice*0.33;
walletProbDistribution = WalletBalanceGenerator(initialCapitalization, 0.00000001);
rwg = PurchaseGenerator(pool, n, 0.5, 0.001, walletProbDistribution);
TestCase.verifyEqual(rwg.P(1), 0.5);
TestCase.verifyEqual(rwg.sigma, 0.001);
TestCase.verifyEqual(size(rwg.P), [1 n]);
end
function testGenerate(TestCase)
T_a = Token("TokenA");
T_b = Token("TokenB");
Q_a = 100000;
Q_b = 10000;
pool = LiquidityPool(T_a, T_b, Q_a, Q_b);
n = 100000;
initialTaPrice = 1;
totalTokenSupply = Q_a*initialTaPrice;
totalFreeTokenSupply = totalTokenSupply/2;
walletProbDistribution = WalletBalanceGenerator(totalTokenSupply, 0.00000001);
rwg = PurchaseGenerator(pool, n, 0.5, 0.001, walletProbDistribution);
t = rwg.rndPurchase(totalFreeTokenSupply, totalTokenSupply);
condition = false;
if (t.is_equal(T_a) || t.is_equal(T_b))
condition = true;
end
TestCase.verifyEqual(condition, true);
end
function testPVariation(TestCase)
T_a = Token("TokenA");
T_b = Token("TokenB");
Q_a = 100000;
Q_b = 10000;
pool = LiquidityPool(T_a, T_b, Q_a, Q_b);
n = 1000;
initialTaPrice = 1;
totalTokenSupply = Q_a*initialTaPrice;
totalFreeTokenSupply = totalTokenSupply/2;
sigma = 0.0001;
walletProbDistribution = WalletBalanceGenerator(totalTokenSupply, 0.00000001);
rwg = PurchaseGenerator(pool, n, 0.5, sigma, walletProbDistribution);
td = zeros(1, n);
for i = 1:n
t = rwg.rndPurchase(totalFreeTokenSupply, totalTokenSupply);
if t.is_equal(T_a)
td(i) = 0;
else
td(i) = 1;
end
end
P = rwg.P;
figure(1);
plot(P);
xlim([1 n]);
end
function testRandomQuantityGeneration(TestCase)
T_a = Token("TokenA");
T_b = Token("TokenB");
Q_a = 100000;
Q_b = 100000;
pool = LiquidityPool(T_a, T_b, Q_a, Q_b);
n = 1000;
initialTaPrice = 1;
totalTokenSupply = Q_a*initialTaPrice;
totalFreeTokenSupply = totalTokenSupply/2;
walletProbDistribution = WalletBalanceGenerator(totalTokenSupply, 0.00000001);
rwg = PurchaseGenerator(pool, n, 0.5, 0.001, walletProbDistribution);
q = zeros(1, n);
for j = 1:n
q(j) = rwg.generateRandomQuantity(totalTokenSupply/totalFreeTokenSupply, initialTaPrice);
end
histogram(q);
end
end
end