11import pytest
2-
3- from dglabv3 .dtype import (
4- ChannelStrength ,
5- Channel ,
6- StrengthType ,
7- StrengthMode ,
8- MessageType ,
9- )
2+ import random
3+ from dglabv3 .dtype import ChannelStrength , Channel , StrengthType , StrengthMode , MessageType , Button
104
115
126def test_channel_strength_initialization ():
137 cs = ChannelStrength ()
148 assert cs .A == 0
159 assert cs .B == 0
10+ assert cs .MAX_A == 200
11+ assert cs .MAX_B == 200
1612
1713
1814def test_channel_strength_set_valid_values ():
1915 cs = ChannelStrength ()
2016 cs .A = 100
2117 cs .B = 150
18+ cs .MAX_A = 160
19+ cs .MAX_B = 160
2220 assert cs .A == 100
2321 assert cs .B == 150
22+ assert cs .MAX_A == 160
23+ assert cs .MAX_B == 160
2424
2525
2626def test_channel_strength_set_invalid_values ():
@@ -35,6 +35,26 @@ def test_channel_strength_set_invalid_values():
3535 cs .B = - 1
3636
3737
38+ def test_channel_strength_set_invalid_max_values ():
39+ cs = ChannelStrength ()
40+ with pytest .raises (ValueError , match = "MAX_A cannot be less than 0" ):
41+ cs .MAX_A = - 1
42+ with pytest .raises (ValueError , match = "MAX_B cannot be less than 0" ):
43+ cs .MAX_B = - 1
44+
45+
46+ def test_channel_strength_set_random_values ():
47+ cs = ChannelStrength ()
48+ maxa = random .randint (50 , 200 )
49+ maxb = random .randint (50 , 200 )
50+ cs .MAX_A = maxa
51+ cs .MAX_B = maxb
52+ with pytest .raises (ValueError , match = f"stronger A cannot be greater than { maxa } " ):
53+ cs .A = maxa + 1
54+ with pytest .raises (ValueError , match = f"stronger B cannot be greater than { maxb } " ):
55+ cs .B = maxb + 1
56+
57+
3858def test_channel_enum ():
3959 assert Channel .A == 1
4060 assert Channel .B == 2
@@ -55,8 +75,17 @@ def test_strength_mode_enum():
5575
5676
5777def test_message_type_enum ():
58- assert MessageType .SET_CHANNEL == "set channel"
5978 assert MessageType .HEARTBEAT == "heartbeat"
79+ assert MessageType .SET_CHANNEL == "set channel"
6080 assert MessageType .BIND == "bind"
6181 assert MessageType .CLIENT_MSG == "clientMsg"
6282 assert MessageType .MSG == "msg"
83+
84+
85+ def test_button ():
86+ assert Button .button_1 == "1"
87+ assert Button .button_2 == "2"
88+ assert Button .button_3 == "3"
89+ assert Button .button_4 == "4"
90+ assert Button .button_5 == "5"
91+ assert Button .button_6 == "6"
0 commit comments