1
1
using EliteAPI . Configuration . Settings ;
2
2
using EliteAPI . Models . Entities . Hypixel ;
3
3
using EliteAPI . Parsers . Farming ;
4
+ using EliteAPI . Utilities ;
5
+ using Microsoft . Extensions . Configuration ;
6
+ using Microsoft . Extensions . DependencyInjection ;
7
+ using Microsoft . Extensions . Options ;
4
8
5
9
namespace EliteAPI . Tests . ParserTests ;
6
10
7
11
public class PestParserTests {
8
-
9
12
[ Fact ]
10
13
public void ParsePestCropCollectionNumbersTest ( ) {
11
- PestParser . CalcUncountedCrops ( Pest . Mite , 0 ) . Should ( ) . Be ( 0 ) ;
12
- PestParser . CalcUncountedCrops ( Pest . Mite , 25 ) . Should ( ) . Be ( 0 ) ;
13
- PestParser . CalcUncountedCrops ( Pest . Mite , 50 ) . Should ( ) . Be ( 0 ) ;
14
- PestParser . CalcUncountedCrops ( Pest . Mite , 51 ) . Should ( )
15
- . Be ( ( int ) Math . Ceiling ( FarmingItemsConfig . Settings . PestCropDropChances [ Pest . Mite ] . GetCropsDropped ( 250 ) * 1 ) ) ;
14
+ var configurationBuilder = new ConfigurationBuilder ( ) ;
15
+ configurationBuilder . RegisterEliteConfigFiles ( ) ;
16
+ var configuration = configurationBuilder . Build ( ) ;
17
+
18
+ var services = new ServiceCollection ( ) ;
19
+ services . Configure < ConfigFarmingWeightSettings > ( configuration . GetSection ( "FarmingWeight" ) ) ;
20
+ var serviceProvider = services . BuildServiceProvider ( ) ;
21
+
22
+ var weightConfig = serviceProvider . GetRequiredService < IOptions < ConfigFarmingWeightSettings > > ( ) . Value ;
16
23
17
- PestParser . CalcUncountedCrops ( Pest . Cricket , 426 ) . Should ( ) . Be ( 834343 ) ;
24
+ PestParser . CalcUncountedCrops ( Pest . Mite , 0 , weightConfig ) . Should ( ) . Be ( 0 ) ;
25
+ PestParser . CalcUncountedCrops ( Pest . Mite , 25 , weightConfig ) . Should ( ) . Be ( 0 ) ;
26
+ PestParser . CalcUncountedCrops ( Pest . Mite , 50 , weightConfig ) . Should ( ) . Be ( 0 ) ;
27
+ PestParser . CalcUncountedCrops ( Pest . Mite , 51 , weightConfig ) . Should ( )
28
+ . Be ( ( int ) Math . Ceiling ( weightConfig . PestCropDropChances [ Pest . Mite ] . GetCropsToSubtract ( 250 , weightConfig : weightConfig ) * 1 ) ) ;
29
+
30
+ PestParser . CalcUncountedCrops ( Pest . Cricket , 426 , weightConfig ) . Should ( ) . Be ( 370802 ) ;
18
31
}
19
32
20
33
[ Fact ]
21
34
public void PestCollectionsTest ( ) {
22
- FarmingItemsConfig . Settings . PestCropDropChances [ Pest . Slug ] . GetCropsDropped ( 1300 , true , false )
23
- . Should ( ) . BeApproximately ( 2402.13 , 0.01 ) ;
35
+ var configurationBuilder = new ConfigurationBuilder ( ) ;
36
+ configurationBuilder . RegisterEliteConfigFiles ( ) ;
37
+ var configuration = configurationBuilder . Build ( ) ;
24
38
25
- FarmingItemsConfig . Settings . PestCropDropChances [ Pest . Slug ] . GetCropsDropped ( 0 , true , false )
26
- . Should ( ) . BeApproximately ( 211.2 , 0.01 ) ;
39
+ var services = new ServiceCollection ( ) ;
40
+ services . Configure < ConfigFarmingWeightSettings > ( configuration . GetSection ( "FarmingWeight" ) ) ;
41
+ var serviceProvider = services . BuildServiceProvider ( ) ;
27
42
28
- FarmingItemsConfig . Settings . PestCropDropChances [ Pest . Fly ] . GetCropsDropped ( 1300 , true , false )
29
- . Should ( ) . BeApproximately ( 24053.76 , 0.01 ) ;
43
+ var weightConfig = serviceProvider . GetRequiredService < IOptions < ConfigFarmingWeightSettings > > ( ) . Value ;
30
44
31
- FarmingItemsConfig . Settings . PestCropDropChances [ Pest . Fly ] . GetCropsDropped ( 0 , true , false )
32
- . Should ( ) . BeApproximately ( 3162.24 , 0.01 ) ;
33
- }
34
-
35
-
36
- public PestParserTests ( ) {
37
- FarmingItemsConfig . Settings . PestDropBrackets = new Dictionary < string , int > {
38
- { "0" , 0 } , { "50" , 250 } , { "100" , 500 } , { "250" , 750 } ,
39
- { "500" , 1000 } , { "750" , 1250 } , { "1000" , 1500 }
40
- } ;
41
-
42
- FarmingItemsConfig . Settings . PestCropDropChances = new Dictionary < Pest , PestDropChance > {
43
- {
44
- Pest . Mite , new ( ) {
45
- Base = 160 ,
46
- Rare = [
47
- new PestRngDrop {
48
- Drops = 25600 ,
49
- Chance = 0.02
50
- }
51
- ]
52
- }
53
- } , {
54
- Pest . Cricket , new ( ) {
55
- Base = 160 ,
56
- Rare = [
57
- new PestRngDrop {
58
- Drops = 20480 ,
59
- Chance = 0.03
60
- }
61
- ]
62
- }
63
- } , {
64
- Pest . Moth , new ( ) {
65
- Base = 160 ,
66
- Rare = [
67
- new PestRngDrop {
68
- Drops = 20480 ,
69
- Chance = 0.03
70
- }
71
- ]
72
- }
73
- } , {
74
- Pest . Earthworm , new ( ) {
75
- Base = 160 ,
76
- Rare = [
77
- new PestRngDrop {
78
- Drops = 25600 ,
79
- Chance = 0.04
80
- }
81
- ]
82
- }
83
- } , {
84
- Pest . Slug , new ( ) {
85
- Base = 160 ,
86
- Rare = [
87
- new PestRngDrop {
88
- Drops = 5120 ,
89
- Chance = 0.005
90
- } ,
91
- new PestRngDrop {
92
- Drops = 5120 ,
93
- Chance = 0.005
94
- }
95
- ]
96
- }
97
- } , {
98
- Pest . Beetle , new ( ) {
99
- Base = 160 ,
100
- Rare = [
101
- new PestRngDrop {
102
- Drops = 25600 ,
103
- Chance = 0.03
104
- }
105
- ]
106
- }
107
- } , {
108
- Pest . Locust , new ( ) {
109
- Base = 160 ,
110
- Rare = [
111
- new PestRngDrop {
112
- Drops = 25600 ,
113
- Chance = 0.03
114
- }
115
- ]
116
- }
117
- } , {
118
- Pest . Rat , new ( ) {
119
- Base = 160 ,
120
- Rare = [
121
- new PestRngDrop {
122
- Drops = 25600 ,
123
- Chance = 0.01
124
- }
125
- ]
126
- }
127
- } , {
128
- Pest . Mosquito , new ( ) {
129
- Base = 160 ,
130
- Rare = [
131
- new PestRngDrop {
132
- Drops = 25600 ,
133
- Chance = 0.02
134
- }
135
- ]
136
- }
137
- } , {
138
- Pest . Fly , new ( ) {
139
- Base = 1296 ,
140
- Rare = [
141
- new PestRngDrop {
142
- Drops = 186624 ,
143
- Chance = 0.01
144
- }
145
- ]
146
- }
147
- }
148
- } ;
45
+ weightConfig . PestCropDropChances [ Pest . Slug ] . GetCropsToSubtract ( 1300 , true , false , weightConfig )
46
+ . Should ( ) . BeApproximately ( 662.77 , 0.01 ) ;
47
+
48
+ weightConfig . PestCropDropChances [ Pest . Slug ] . GetCropsToSubtract ( 0 , true , false , weightConfig )
49
+ . Should ( ) . BeApproximately ( 49.26 , 0.01 ) ;
50
+
51
+ weightConfig . PestCropDropChances [ Pest . Fly ] . GetCropsToSubtract ( 1300 , true , false , weightConfig )
52
+ . Should ( ) . BeApproximately ( 0.0 , 0.01 ) ;
53
+
54
+ weightConfig . PestCropDropChances [ Pest . Fly ] . GetCropsToSubtract ( 0 , true , false , weightConfig )
55
+ . Should ( ) . BeApproximately ( 0.0 , 0.01 ) ;
149
56
}
150
57
}
0 commit comments