Example #1
0
    def test_intensity_scalers_as_function_vs_list(self, format):
        """Test that both functions and lists work the same."""
        def intensity_scaler_func(week):
            return 1 - week / 100

        intensity_scalers = [(1 - week / 100) for week in range(1, 9)]

        program1 = Program("My first program!",
                           duration=8,
                           round_to=1,
                           intensity_scaler_func=intensity_scaler_func)
        with program1.Day():
            program1.DynamicExercise("Bench press", start_weight=100)
        program1.render()

        program2 = Program("My first program!",
                           duration=8,
                           round_to=1,
                           intensity_scaler_func=intensity_scalers)
        with program2.Day():
            program2.DynamicExercise("Bench press", start_weight=100)
        program2.render()

        # Use .txt format to compare programs
        assert getattr(program1,
                       f"to_{format}")() == getattr(program2, f"to_{format}")()
Example #2
0
def test_program_not_mutated_after_rendering():
    """Creating and rendering a program should not mutate its dict
    representations."""

    # Set some non-typical parameters
    program = Program(
        name="MyProgram",
        duration=5,
        min_reps=1,
        reps_per_exercise=31,
        round_to=10,
        rep_scaler_func=[0.99, 0.97, 0.96, 0.95, 0.98],
        intensity_scaler_func=[0.99, 0.97, 0.96, 0.95, 0.98],
        units="asdf",
    )
    with program.Day("A"):
        program.DynamicExercise("Squats",
                                start_weight=100,
                                final_weight=113,
                                max_reps=12)

    program_serialized = program.serialize()
    program.render()
    program_dict = program.to_dict()

    # Rendering the program should not change the serialization
    assert program.serialize() == program_serialized

    # Serializing and de-serializing should not change the program dict reprs
    program = Program.deserialize(program.serialize())
    program.render()
    assert program.serialize() == program_serialized
    assert program_dict == program.to_dict()
Example #3
0
def test_error_on_non_unique_exercise_names():
    """Test that using the same exercise name raises an error."""

    program1 = Program(duration=8, round_to=1)
    with program1.Day():
        program1.DynamicExercise("Bench press",
                                 start_weight=100,
                                 min_reps=4,
                                 max_reps=7)
        program1.DynamicExercise("Bench press",
                                 start_weight=90,
                                 min_reps=1,
                                 max_reps=7)

    with pytest.raises(ValueError,
                       match="Exercise name not unique: Bench press"):
        program1.render()
Example #4
0
    def test_inc_week_program_vs_exercise(self, format):
        """Test that giving progress in program or exercise is the same."""

        program1 = Program(duration=8, round_to=1)
        with program1.Day():
            program1.DynamicExercise("Bench press",
                                     start_weight=100,
                                     percent_inc_per_week=2)
        program1.render()

        program2 = Program(duration=8, round_to=1, percent_inc_per_week=2)
        with program2.Day():
            program2.DynamicExercise("Bench press", start_weight=100)
        program2.render()

        # Use .txt format to compare programs
        assert getattr(program1,
                       f"to_{format}")() == getattr(program2, f"to_{format}")()
Example #5
0
    def test_progress_information_calcs_from_program(self):
        program = Program(name="MyProgram",
                          duration=10,
                          percent_inc_per_week=10)

        # Three ways of saying the same thing
        with program.Day():
            a = program.DynamicExercise("a", start_weight=100)
            b = program.DynamicExercise("b",
                                        start_weight=100,
                                        final_weight=200)
            c = program.DynamicExercise("c", final_weight=200)

        a_info = a._progress_information()
        b_info = b._progress_information()
        c_info = c._progress_information()

        assert a_info == b_info
        assert b_info == c_info
Example #6
0
    def test_progress_information_overspecified(self):

        # Set some non-typical parameters
        program = Program(name="MyProgram", duration=10)
        with pytest.raises(ValueError,
                           match="At most 2 out of 3 variables may be set"):
            with program.Day("A"):
                program.DynamicExercise("Squats",
                                        start_weight=100,
                                        final_weight=150,
                                        percent_inc_per_week=10)
Example #7
0
    def test_rep_range_exercise_vs_program(self, format):
        """Test that giving rep range in program or exercise is the same."""

        program1 = Program("My first program!", duration=8, round_to=1)
        with program1.Day():
            program1.DynamicExercise("Bench press",
                                     start_weight=100,
                                     min_reps=4,
                                     max_reps=7)
        program1.render()

        program2 = Program("My first program!",
                           duration=8,
                           round_to=1,
                           min_reps=4,
                           max_reps=7)
        with program2.Day():
            program2.DynamicExercise("Bench press", start_weight=100)
        program2.render()

        # Use formats to compare programs
        assert getattr(program1,
                       f"to_{format}")() == getattr(program2, f"to_{format}")()
Example #8
0
    def test_progress_information_override_perc_inc(self):

        program = Program(name="MyProgram",
                          duration=10,
                          percent_inc_per_week=1)
        with program.Day("A"):
            squat = program.DynamicExercise("Squats",
                                            start_weight=100,
                                            percent_inc_per_week=10)

        (start_w, final_w, inc_week) = squat._progress_information()
        assert start_w == 100
        assert final_w == 200
        assert inc_week == 10  # Weight override program default
Example #9
0
def test_decorator_api():
    """The new API."""
    def curl_func(week):
        return "{} x 10".format(week)

    # Create a 4-week program
    program = Program("My first program!", duration=8)

    with program.Day():

        program.DynamicExercise("Bench press", 60, 65)
        program.DynamicExercise("Squats", 80, 85)
        program.StaticExercise("Curls", curl_func)

    assert len(program.days) == 1
    assert len(program.days[0].dynamic_exercises) == 2
    assert len(program.days[0].static_exercises) == 1

    assert program.days[0].program is not None
    assert program.days[0].dynamic_exercises[0].day is not None

    assert not program._rendered
    program.render()
    assert program._rendered
Example #10
0
    def test_Program(self):
        """Serialize and deserialize should be equal."""

        program = Program(name="Beginner 5x5",
                          duration=4,
                          intensity=85,
                          units="kg",
                          round_to=2.5,
                          rep_scaler_func=[1, 1, 1, 1])

        with program.Day("A"):
            program.DynamicExercise(name="Squat", start_weight=100)

        program.render()

        # Create a new program by serializing and deserializing
        new_program = Program.deserialize(program.serialize())
        new_program.render()

        assert str(program) == str(new_program)
Example #11
0
    program = Program(
        "My first program!",
        duration=8,
        units="kg",
        reps_per_exercise=15,
        intensity=88,
        intensity_scaler_func=lambda w: 1,
        round_to=2.5,
        percent_inc_per_week=2,
        verbose=True,
    )

    with program.Day("Mandag"):
        program.DynamicExercise("Knebøy",
                                start_weight=100,
                                min_reps=3,
                                max_reps=5)

    # Render the program, then print it
    program.render()
    from pprint import pprint

    # pprint(program.to_dict())
    print(program)

    def rep_scaler_func(week, *args):
        return 1

    def intensity_scaler_func(week, *args):
        return 1