Commit f577a2d8 authored by sparonuz's avatar sparonuz
Browse files

[Issue#114]: Updated test for getter

parent eb18e623
......@@ -2,6 +2,7 @@ import unittest
import AutoRPE.UtilsRPE.Getter as Getter
import AutoRPE.UtilsRPE.VariablePrecision as VariablePrecision
class TestGetter(unittest.TestCase):
def test_get_function_type(self):
......@@ -26,39 +27,40 @@ class TestGetter(unittest.TestCase):
string = "rpe(Kmm)"
self.assertEqual(Getter.get_function_type(string, subroutine, vault), 'rpe_var')
string = "float(Kmm)"
self.assertEqual(Getter.get_function_type(string, subroutine, vault), VariablePrecision.wp)
self.assertEqual(Getter.get_function_type(string, subroutine, vault), VariablePrecision.real_id['wp'])
def test_type_of_real_cast_with_double_specification(self):
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),dp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'double')
self.assertEqual(Getter.get_type_of_real_cast(string), 'dp')
def test_type_of_real_cast_with_single_specification(self):
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),sp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'single')
self.assertEqual(Getter.get_type_of_real_cast(string), VariablePrecision.real_id['sp'])
def test_type_of_real_cast_no_specification(self):
from AutoRPE.UtilsRPE.VariablePrecision import wp
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1))'
self.assertEqual(Getter.get_type_of_real_cast(string), wp)
self.assertEqual(Getter.get_type_of_real_cast(string), VariablePrecision.real_id['wp'])
def test_set_working_precision(self):
VariablePrecision.set_working_precision("sp")
self.assertEqual(VariablePrecision.real_id['wp'], VariablePrecision.real_id['sp'])
VariablePrecision.set_working_precision("dp")
self.assertEqual(VariablePrecision.real_id['wp'], VariablePrecision.real_id['dp'])
def test_dimension_of_contents_1(self):
import AutoRPE.UtilsRPE.Getter as Getter
self.assertEqual(Getter.get_dimension_of_contents("1.0"), 0)
def test_dimension_of_contents_2(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "real( ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 3)
def test_dimension_of_contents_3(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "e1e2t(:,:) * zfwf(:,:)"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 2)
def test_dimension_of_contents(self):
import AutoRPE.UtilsRPE.Getter as Getter
cases = [
('SUM( a_i(:,:,:)%val - a_i_b(:,:,:)%val, dim=3 )', 2),
('SQRT( ( zs1(:,:)%val - zs2(:,:)%val )**2 + 4*zs12(:,:)%val**2 ) * zmsk00(:,:)', 2)
......@@ -68,7 +70,6 @@ class TestGetter(unittest.TestCase):
# Simple Array
def test_clean_remove_indexing_1(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'uu(:,:,:,Kmm)'
result = Getter.remove_indexing(string)
expected_result = "uu"
......@@ -76,7 +77,6 @@ class TestGetter(unittest.TestCase):
# Array with array indexing
def test_clean_remove_indexing_2(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'zz_read(1:nblendta(igrd,ib_bdy),:)'
result = Getter.remove_indexing(string)
expected_result = "zz_read"
......@@ -84,7 +84,6 @@ class TestGetter(unittest.TestCase):
# Structure with array member
def test_clean_remove_indexing_3(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'idx_bdy(ib_bdy)%ntreat(ib,igrd)'
result = Getter.remove_indexing(string)
expected_result = 'idx_bdy%ntreat'
......@@ -92,7 +91,6 @@ class TestGetter(unittest.TestCase):
# Structure with structure indexing
def test_clean_remove_indexing_4(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'sdjf%nrecsec(1:sdjf%nreclast)'
result = Getter.remove_indexing(string)
expected_result = "sdjf%nrecsec"
......@@ -100,4 +98,4 @@ class TestGetter(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
unittest.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