forked from YoRyan/nuxhash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_naive_switcher.py
61 lines (43 loc) · 2.14 KB
/
test_naive_switcher.py
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
from pathlib import Path
from unittest import main, TestCase
import nuxhash.settings
import tests
from nuxhash.miners.excavator import Excavator
from nuxhash.switching.naive import NaiveSwitcher
class TestNaiveSwitcher(TestCase):
def setUp(self):
settings = nuxhash.settings.DEFAULT_SETTINGS
settings['switching']['threshold'] = 0.5
self.devices = tests.get_test_devices()
self.benchmarks = tests.get_test_benchmarks()
self.miner = Excavator(Path('/'))
self.equihash = next(a for a in self.miner.algorithms
if a.algorithms == ['equihash'])
self.neoscrypt = next(a for a in self.miner.algorithms
if a.algorithms == ['neoscrypt'])
self.switcher = NaiveSwitcher(settings)
self.switcher.reset()
def test_most_profitable(self):
device = self.devices[0]
equihash_revenue = 4.0*self.benchmarks[device]['excavator_equihash'][0]
neoscrypt_revenue = 2.0*self.benchmarks[device]['excavator_neoscrypt'][0]
revenues = { device: { self.equihash: equihash_revenue,
self.neoscrypt: neoscrypt_revenue } }
decision = self.switcher.decide(revenues, None)
self.assertEqual(decision[device], self.neoscrypt)
def test_below_threshold(self):
device = self.devices[0]
self.switcher.decide({ device: { self.equihash: 2.0,
self.neoscrypt: 1.0 } }, None)
decision = self.switcher.decide({ device: { self.equihash: 2.0,
self.neoscrypt: 2.5 } }, None)
self.assertEqual(decision[device], self.equihash)
def test_above_threshold(self):
device = self.devices[0]
self.switcher.decide({ device: { self.equihash: 2.0,
self.neoscrypt: 1.0 } }, None)
decision = self.switcher.decide({ device: { self.equihash: 2.0,
self.neoscrypt: 3.5 } }, None)
self.assertEqual(decision[device], self.neoscrypt)
if __name__ == '__main__':
main()