Commit a5d3ed71 authored by Simeon Doetsch's avatar Simeon Doetsch

Added IO test

parent 99d0e825
def generate_gridfile(filename='grid.out', dims=(10,9,8)):
with open(filename, 'w') as f:
f.write('# FILE HEADER\n')
for res in dims:
for i in range(res):
f.write(f' {i} {i:.12e} {i+1:.12e}\n')
if __name__ == '__main__':
import unittest
import os
import numpy as np
from import Grid
from generate_testdata import generate_gridfile
class TestGrid(unittest.TestCase):
def setUp(self):
self.file = 'gridtest.out'
self.dims = (10, 11, 12)
generate_gridfile(self.file, self.dims)
self.grid = Grid(self.file)
def tearDown(self):
def testDimensions(self):
self.assertEqual(self.dims, self.grid.dims)
self.assertEqual(self.dims, self.grid.data_shape)
def testData(self):
for i, res in enumerate(self.dims, start=1):
x = getattr(self.grid, f'x{i}')
dx = getattr(self.grid, f'dx{i}')
np.testing.assert_array_almost_equal_nulp(x, np.arange(0.5, res, 1))
np.testing.assert_array_almost_equal_nulp(dx, np.ones(res))
if __name__ == '__main__':
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment