This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest-gym.lua
71 lines (59 loc) · 1.98 KB
/
test-gym.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local torch = require 'torch'
local api = torch.TestSuite()
local atari = torch.TestSuite()
local mujoco = torch.TestSuite()
local experiment = torch.TestSuite()
local tester = torch.Tester()
local gymClient = require '../src/gym-http-api/binding-lua/gym_http_client'
-- disable rendering and video for testing
local verbose = false
local render = false
local video_callable = 0
local runTest = require '../src/gym-http-api/binding-lua/test_api'({
gymClient = gymClient,
verbose = verbose,
render = render,
video_callable = video_callable
})
function api.testCartPole()
local success = runTest('CartPole-v0')
tester:eq(success, true, "testCartPole shouldn't give an error")
end
function api.testPendulum()
local success = runTest('Pendulum-v0')
tester:eq(success, true, "testPendulum shouldn't give an error")
end
function api.testFrozenLake()
local success = runTest('FrozenLake-v0')
tester:eq(success, true, "testCartPole shouldn't give an error")
end
function atari.testAtari()
local success = runTest('BattleZone-v0')
tester:eq(success, true, "testAtari shouldn't give an error if you have Atari configured")
end
function mujoco.testMujoco()
local success = runTest('InvertedPendulum-v1')
tester:eq(success, true, "testMujoco shouldn't give an error if you have MuJoCo configured")
end
function experiment.badExperimentCall()
local performance = require 'twrl.experiment'()
tester:eq(performance, {}, "bad experiment call should fail with bad settings ")
end
function experiment.randomNoLearningNoModel()
local env = 'CartPole-v0'
local params = {}
local agent = {
policy = 'random',
learningUpdate = 'noLearning',
model = 'noModel'
}
local nSteps = 2
local nIterations = 2
local performance = require 'twrl.experiment'(env, agent, nSteps, nIterations, params)
tester:eq(performance.iteration, 2, "basic experiment should run")
end
tester:add(api)
tester:add(atari)
tester:add(mujoco)
tester:add(experiment)
tester:run()