Download the file
  1. import pytest
  2. from nerdle import *
  3.  
  4. @pytest.fixture
  5. def solver():
  6. s = Solver()
  7. s.record("8+7*6=50", "aaaaiiii")
  8. return s
  9.  
  10.  
  11. def test1(solver):
  12. assert solver.next_set([]) == solver.digits - ZERO
  13.  
  14. def test2(solver):
  15. assert solver.next_set(['5']) == solver.digits | solver.operators
  16.  
  17. def test3(solver):
  18. assert solver.next_set(['5', '-']) == solver.digits - ZERO
  19.  
  20. def test4(solver):
  21. assert solver.next_set(['5', '5']) == solver.digits | solver.operators
  22.  
  23. def test5(solver):
  24. assert solver.next_set(['5', '-', '5']) == solver.digits | solver.operators | EQUAL
  25.  
  26. def test6(solver):
  27. assert solver.next_set(['5', '-', '5', '5']) == solver.digits | solver.operators | EQUAL
  28.  
  29. def test7(solver):
  30. assert solver.next_set(['5', '5', '-', '5', '5' ]) == solver.digits | solver.operators | EQUAL
  31.  
  32. def test8(solver):
  33. assert solver.next_set(['5', '5', '-', '5', '-', '5']) == EQUAL
  34.  
  35. def test9(solver):
  36. assert solver.next_set(['5', '5', '-', '5', '-', '5', '=']) == solver.digits
  37.  
  38. def test10(solver):
  39. assert solver.next_set(['5', '5', '-', '5', '-', '5', '=', '5']) == solver.digits
  40.  
  41. def test11(solver):
  42. assert solver.next_set(['5', '-']) == solver.digits - ZERO
  43.  
  44. def test50():
  45. s = Solver()
  46. s.record("8+7*6=50", "aaaaiiii")
  47. assert s.operators == OPERATORS - {'+', '*'}
  48. assert s.digits == DIGITS - {'8', '7'}
  49. assert s.corrects == [None] * 8
  50. assert s.incorrects == [{'8'}, {'+'}, {'7'}, {'*'}, {'6'}, {'='}, {'5'}, {'0'}]
  51.  
  52. def test101():
  53. s = Solver()
  54. s.record("8+7*6=50", "caiiiiaa")
  55. s.record("8-12/3=4", "caaiaiia")
  56. assert (-12, "88*9=792") in s._solutions()
  57. s.record("88*9=792", "caciciai")
  58. assert s._solutions() == {(-16, '89*7=623'), (-16, '89*3=267') }
  59. s.record("89*7=623", "ccciciii")
  60. assert s._solutions() == {(-16, "89*3=267")}
  61.  
  62. def test102():
  63. s = Solver()
  64. s.record("8+7*6=50", "iaaaaiai")
  65. assert (-16, "9-24/3=1") in s._solutions()
  66. s.record("9-24/3=1", "iiiaaaci")
  67. assert s._solutions() == {(-14, "100-98=2"), (-14, "100-92=8")}
  68. s.record("100-98=2", "cccccccc")
  69. assert s._solutions() == {(-14, "100-98=2")}
  70.  
  71. def test103():
  72. s = Solver()
  73. s.record("8+7*6=50", "iaaaacia")
  74. s.record("129/3=43", "aaiaacca")
  75. assert s.digits == {'4', '5', '8', '9'}
  76. assert s.operators == {'-'}
  77. assert (-10, "94-45=49") in s._solutions()
  78. s.record("94-45=49", "ciciicca")
  79. assert s._solutions() == {(-12, "98-54=44")}
  80.  
  81. def test104():
  82. s = Solver()
  83. s.record("8+7*6=50", "icaaaiia")
  84. s.record("1+24/3=9", "iciaaaci")
  85. s.record("2+11-5=8", "iccacicc")
  86. assert s._solutions() == {(-16, "5+12-9=8")}
  87.  
  88. def test105():
  89. s = Solver()
  90. s.record("8+7*6=50", "iaaaicaa")
  91. s.record("129/3=43", "iaacacia")
  92. assert (1, "44//4=11") not in s._solutions()
  93.  
  94. def test106():
  95. s = Solver()
  96. s.record("8+7*6=50", "iiaaacia")
  97. s.record("129/3=43", "aaaaicia")
  98. assert s.score('54+34=88') < s.score('44+44=88')
  99.