Skip to content

Commit

Permalink
test: reorganize and test x_loop_gate
Browse files Browse the repository at this point in the history
  • Loading branch information
unRARed committed Dec 1, 2024
1 parent f2b4d4d commit 886aaf2
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 81 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ For latest, see
interact with it.
- **Production** - `bin/run` will run for production using the real
hardware devices and the console GUI.
- **Test** - `bin/test` will run all tests from the `./tests` folder.
- **Test** - Run a test with `bin/test tests/test_something.py` or
simply `bin/test` to run all tests from the `./tests` folder.
2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python -m unittest -v
python -m unittest -v $1
2 changes: 1 addition & 1 deletion modes/base/config/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mode:
start_events: ball_starting
priority: 100
priority: 50

ball_saves:
ball_start_ball_save:
Expand Down
20 changes: 20 additions & 0 deletions modes/green_flag/config/green_flag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ mode:
restart_on_next_ball: true
priority: 100

light_player:
mode_green_flag_started:
x_loop_gate:
color: white

variable_player:
mode_green_flag_started:
level_green_flag:
action: add
int: 1

###########
# Scoring #
###########

s_spinner_active:
score:
int: 20 * (current_player.level_green_flag + 1)
block: true
s_grooveline_active:
score:
int: 500 * (current_player.level_green_flag + 1)
block: true
bonus:
int: 50 * (current_player.level_green_flag + 1)
38 changes: 38 additions & 0 deletions tests/death_save_game_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
from mpf.core.rgb_color import RGBColor
from mpf.tests.MpfGameTestCase import MpfGameTestCase

class DeathSaveGameTesting(MpfGameTestCase):

def get_config_file(self):
return 'development.yaml'

def get_machine_path(self):
return os.path.abspath(os.path.join(
os.path.realpath(__file__),
os.pardir,os.pardir
))

##################
# Helper Methods #
##################

# For given :var, activate given :switch and check
# whether value has increased by given :value
#
# @param var: variable to check (score, bonus, etc.)
# @param switch: switch to activate (s_spinner, s_pop1, etc.)
# @param value: amount we expect the :var to increase by
#
# Example: self.assertIncrement("score", "s_spinner", 10)
#
def assertIncrement(self, var, switch, value):
current_val = getattr(self.machine.game.player, var)
value, getattr(self.machine.game.player, var)
self.hit_and_release_switch(switch)
self.advance_time_and_run(1)
new_val = getattr(self.machine.game.player, var)
self.assertEqual(
value, new_val - current_val,
"Expected %s, got %s" % (value, new_val - current_val)
)
76 changes: 27 additions & 49 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
"""Tests Base Mode"""
import os
from tests.death_save_game_testing import DeathSaveGameTesting

from mpf.tests.MpfGameTestCase import MpfGameTestCase

class TestBase(MpfGameTestCase):

def get_config_file(self):
return 'development.yaml'

def get_machine_path(self):
return os.path.abspath(os.path.join(
os.path.realpath(__file__),
os.pardir,os.pardir
))
class TestBase(DeathSaveGameTesting):

def test_scoring(self):
self.start_game()
v = "score"
score = "score"

score = 0
self.assertEqual(score, self.machine.game.player.score)

self.__increment(v, "s_pop1", 10)
self.__increment(v, "s_pop2", 10)
self.__increment(v, "s_grooveline", 25)
self.__increment(v, "s_qualifier1", 100)
self.__increment(v, "s_qualifier2", 100)
self.__increment(v, "s_qualifier3", 100)
self.__increment(v, "s_podium_hole", 500)
self.__increment(v, "s_prix_hole", 100)
self.__increment(v, "s_grand_hole", 100)
self.__increment(v, "s_spinner", 10)
self.__increment(v, "s_grand_advance", 10)
self.__increment(v, "s_prix_advance", 10)
self.__increment(v, "s_podium_advance1", 10)
self.__increment(v, "s_podium_advance2", 10)
self.__increment(v, "s_slingshot1", 10)
self.__increment(v, "s_slingshot2", 10)
self.__increment(v, "s_inlane1", 25)
self.__increment(v, "s_inlane2", 25)
self.__increment(v, "s_outlane1", 50)
self.__increment(v, "s_outlane2", 50)

def __increment(self, var, switch, value):
current_val = getattr(self.machine.game.player, var)
value, getattr(self.machine.game.player, var)
self.hit_and_release_switch(switch)
self.advance_time_and_run(1)
new_val = getattr(self.machine.game.player, var)
self.assertEqual(
value, new_val - current_val,
"Expected %s, got %s" % (value, new_val - current_val)
)
self.start_game()
self.assertEqual(0, self.machine.game.player.score)
self.assertIncrement(score, "s_pop1", 10)
self.assertIncrement(score, "s_pop2", 10)
self.assertIncrement(score, "s_grooveline", 25)
self.assertIncrement(score, "s_qualifier2", 100)
self.assertIncrement(score, "s_qualifier3", 100)
self.assertIncrement(score, "s_podium_hole", 500)
self.assertIncrement(score, "s_prix_hole", 100)
self.assertIncrement(score, "s_grand_hole", 100)
self.assertIncrement(score, "s_spinner", 10)
self.assertIncrement(score, "s_grand_advance", 10)
self.assertIncrement(score, "s_prix_advance", 10)
self.assertIncrement(score, "s_podium_advance1", 10)
self.assertIncrement(score, "s_podium_advance2", 10)
self.assertIncrement(score, "s_slingshot1", 10)
self.assertIncrement(score, "s_slingshot2", 10)
self.assertIncrement(score, "s_inlane1", 25)
self.assertIncrement(score, "s_inlane2", 25)
self.assertIncrement(score, "s_outlane1", 50)
self.assertIncrement(score, "s_outlane2", 50)
# Activates green_flag mode, so check last
# to prevent scoring false positives
self.assertIncrement(score, "s_qualifier1", 100)
72 changes: 43 additions & 29 deletions tests/test_green_flag.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,70 @@
"""Tests Green Flag Mode"""
import os
from tests.death_save_game_testing import DeathSaveGameTesting
import pprint

from mpf.tests.MpfGameTestCase import MpfGameTestCase
class TestBase(DeathSaveGameTesting):

class TestGreenFlag(MpfGameTestCase):
def test_scoring(self):
score = "score"

def get_config_file(self):
return 'development.yaml'
# Workaround to use the incandescent
# driver for the mini coils
self.assertLightColor('x_loop_gate', 'black')

def get_machine_path(self):
return os.path.abspath(os.path.join(
os.path.realpath(__file__),
os.pardir,os.pardir
))
self.__start_green_flag()

def test_qualification(self):
self.start_game()
self.assertEqual(
0, self.machine.game.player.level_green_flag
)
self.assertModeNotRunning("green_flag")
# Mini coils is activated making it
# possible to complete the loop
self.assertLightColor('x_loop_gate', 'white')

self.hit_and_release_switch("s_qualifier1")
self.advance_time_and_run(1)
self.assertModeRunning("green_flag")
# Green Flag Mode is about the loop
# TODO: Count the number of loops:
# both continuous and in total
self.assertIncrement(score, "s_spinner", 20 * 2)
self.assertIncrement(score, "s_grooveline", 500 * 2)
# Only the grooveline adds to the bonus
self.assertIncrement("bonus", "s_grooveline", 50 * 2)

# Other switches score normally per Base Mode
self.assertIncrement(score, "s_pop1", 10)
self.assertIncrement(score, "s_podium_advance1", 10)
self.assertIncrement(score, "s_slingshot2", 10)


def test_qualification(self):
self.__start_green_flag()
self.assertEqual(
1, self.machine.game.player.level_green_flag
)

self.hit_and_release_switch("s_disqualifier")
self.assertModeNotRunning("green_flag")

# Second time around, it requires hitting two
# qualifiers to start the mode
self.hit_and_release_switch("s_qualifier1")
self.assertModeNotRunning("green_flag")
self.hit_and_release_switch("s_qualifier2")
self.assertModeRunning("green_flag")
self.hit_and_release_switch("s_disqualifier")
self.__qualify_level_two()

# Third time around, it requires hitting
# all three qualifiers
self.__qualify_final_level()

# Further attempts function the same way,
# requiring all 3 qualifiers to be hit
self.__qualify_final_level()

def __start_green_flag(self):
self.start_game()
self.hit_and_release_switch("s_qualifier1")
self.advance_time_and_run(1)
self.assertModeRunning("green_flag")

def __qualify_level_two(self):
self.hit_and_release_switch("s_qualifier1")
self.assertModeNotRunning("green_flag")
self.hit_and_release_switch("s_qualifier2")
self.assertModeNotRunning("green_flag")
self.hit_and_release_switch("s_qualifier3")
self.assertModeRunning("green_flag")
self.hit_and_release_switch("s_disqualifier")

# Further attempts function the same way,
# requiring all 3 qualifiers to be hit
def __qualify_final_level(self):
self.hit_and_release_switch("s_qualifier1")
self.assertModeNotRunning("green_flag")
self.hit_and_release_switch("s_qualifier2")
Expand Down

0 comments on commit 886aaf2

Please sign in to comment.