Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def test_general_api():
    """The slightly more easy API."""
    def curl_func(week):
        return "{} x 10".format(week)

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

    # Create some dynamic and static exercises
    bench = DynamicExercise("Bench press", 60, 70)
    squats = DynamicExercise("Squats", 80, 90)
    curls = StaticExercise("Curls", curl_func)
    day = Day(exercises=[bench, squats, curls])

    # Variable reference to days are added
    assert bench.day is not None
    assert squats.day is not None

    assert len(day.dynamic_exercises) == 2

    # Add day(s) to program and render it
    program.add_days(day)
    assert day.program is not None

    assert len(program.days) == 1

    assert not program._rendered
    program.render()
    assert program._rendered
Ejemplo n.º 4
0
def test_verbose_api(duration):
    """The oldest, most verbose API."""
    def curl_func(week):
        return "{} x 10".format(week)

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

    # Create some dynamic and static exercises
    bench = DynamicExercise("Bench press", 60, 60 * (1 + 0.01 * duration))
    squats = DynamicExercise("Squats", 80, 80 * (1 + 0.01 * duration))
    curls = StaticExercise("Curls", curl_func)

    day = Day()
    day.add_exercises(bench, squats, curls)

    assert len(day.dynamic_exercises) == 2

    # Add day(s) to program and render it
    program.add_days(day)

    assert len(program.days) == 1

    assert not program._rendered
    program.render()
    assert program._rendered
def test_exercisedescription_program():

    with temporary_db("tempfile.db", delete=False):
        engine = create_engine("sqlite:///tempfile.db", echo=True)

        Base.metadata.create_all(engine)
        Session = sessionmaker(bind=engine)
        session = Session()

        ed = ExerciseDescription(name="Bench press",
                                 description="Let's see if this works!")
        session.add(ed)
        session.commit()
        #del session

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

        # Create some dynamic and static exercises
        bench = DynamicExercise('Bench press',
                                start_weight=60,
                                final_weight=80)
        squats = DynamicExercise('Squats', start_weight=80, final_weight=95)
        curls = StaticExercise('Curls', '3 x 12')
        day = Day(exercises=[bench, squats, curls])

        # Add day(s) to program and render it
        program.add_days(day)
        program.render()

        p = program_to_sql(program, engine=engine)
        #session = Session()
        session.commit()
    return program, p
Ejemplo n.º 6
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)
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
def test_dynamic_exercises_are_not_mutated():
    """Creating a program should not mutate an exercise."""

    # Create an exercise
    exercise = DynamicExercise("Bench press", start_weight=100)
    exercise_dict = exercise.serialize()

    # Create a program, add the day and render it
    program = Program()
    day = Day("Monday")
    day.add_exercises(exercise)
    program.add_days(day)
    program.render()

    assert exercise.serialize() == exercise_dict
Ejemplo n.º 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
def test_single_program():
    session = create_memory_session()

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

    # Create some dynamic and static exercises
    bench = DynamicExercise('Bench press', start_weight=60, final_weight=80)
    squats = DynamicExercise('Squats', start_weight=80, final_weight=95)
    curls = StaticExercise('Curls', '3 x 12')
    day = Day(exercises=[bench, squats, curls])

    # Add day(s) to program and render it
    program.add_days(day)
    program.render()

    p = program_to_sql(program)
    return session, program, p
Ejemplo n.º 11
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
Ejemplo n.º 12
0
if __name__ == "__main__":
    import pytest

    pytest.main(args=[".", "--doctest-modules", "-v", "--capture=sys"])

if __name__ == "__main__":

    from streprogen import Program

    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
Ejemplo n.º 13
0
    def test_start_weight_vs_final_weight(self, format):
        """Test that giving progress in program or exercise is the same."""

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

        program2 = Program(duration=3, units="kg", round_to=1)
        with program2.Day():
            program2.DynamicExercise("Bench press",
                                     percent_inc_per_week=2,
                                     final_weight=106)
        program2.render()

        # Use .txt format to compare programs
        assert getattr(program1,
                       f"to_{format}")() == getattr(program2, f"to_{format}")()
Ejemplo n.º 14
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}")()
Ejemplo n.º 15
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}")()
Ejemplo n.º 16
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()