forked from google-deepmind/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_file_test.lua
More file actions
33 lines (27 loc) · 958 Bytes
/
read_file_test.lua
File metadata and controls
33 lines (27 loc) · 958 Bytes
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
local game = require 'dmlab.system.game'
local asserts = require 'testing.asserts'
local test_runner = require 'testing.test_runner'
local helpers = require 'common.helpers'
local FILE_NAME = ...
local EMPTY_FILE_NAME = helpers.dirname(FILE_NAME) .. "data/empty_test_file"
local BINARY_FILE_NAME = helpers.dirname(FILE_NAME) .. "data/testL.png"
local tests = {}
local function readFile(file)
local f = io.open(file, "rb")
local content = f:read("*all")
f:close()
return content
end
function tests:readEmpty()
local emptyFileContent = game:loadFileToString(EMPTY_FILE_NAME)
asserts.EQ(emptyFileContent, '')
end
function tests:readBinaryFile()
local binaryFileContent = game:loadFileToString(BINARY_FILE_NAME)
assert(binaryFileContent == readFile(BINARY_FILE_NAME))
end
function tests:readSelf()
local textFileContent = game:loadFileToString(FILE_NAME)
assert(textFileContent == readFile(FILE_NAME))
end
return test_runner.run(tests)