Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for reward function for one timesteps #17

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_greencrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ def test_GC():
check_env(greenCrabEnv(), warn=True)
check_env(greenCrabSimplifiedEnv(), warn=True)
check_env(timeSeriesEnv(), warn=True)

31 changes: 29 additions & 2 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def test_full_harvest():
steps = env.Tmax
prev_state = env.state # store the state before taking step
for i in range(steps):
observation, rew, term, trunc, info = env.step(np.array([1,1, 1]))
observation, rew, term, trunc, info = env.step(np.array([1,1,1]))
# if crab population drop, catch rate should not be zero
if (sum(prev_state) > sum(env.state)):
assert observation[0] != -1 or observation[1] != -1
assert rew < 0 # try to discourage laying all traps for each timestep

assert info == {}
assert trunc == False
Expand Down Expand Up @@ -74,4 +75,30 @@ def test_reset():
# reset the obseravtion environment
new_ob_space, new_info = env.reset()

assert np.array_equal(new_ob_space, np.array([-1, -1]))
assert np.array_equal(new_ob_space, np.array([-1, -1]))

# test reward function for both greenCrab and greenCrabSimplified
def test_reward_func():
env = greenCrabSimplifiedEnv()
env.reset()
# self.state = self.self.init_state()

# test no trap laid for one timestep when no crab
action = np.array([-1, -1, -1])
assert env.reward_func(action) >= 0 # are we expecting non-negative when no traps laid when no crabs

# test for all trap laid for one timestep when no crab
action = np.array([1, 1, 1])
felimomo marked this conversation as resolved.
Show resolved Hide resolved
assert env.reward_func(action) < 0 # are we expecting positive when no traps laid when no crabs

# test no trap when there is a lot of crabs
env.state = np.array([10., 10., 10., 10., 1000., 10000., 100000., 1000., 100., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.])
action = np.array([-1, -1, -1])
assert env.reward_func(action) < 0 # expecting neg reward

# test all trap laid for one timestep
action = np.array([1, 1, 1])
assert env.reward_func(action) < 0



Loading