<reponame>rphilander/proteus<gh_stars>0
import unittest

from core import Atom
from rows2atoms import transform

headers = ['athlete', 'age', 'country', 'year', 'sport', 'golds', 'silvers', 'bronzes', 'total_medals']

class Rows2AtomsTests(unittest.TestCase):

    def test_empty(self):
        self.assertEqual(list(transform([headers])), [])

    def test_one_row_nine(self):
        row = ['<NAME>', 42, 'Slovenia', 4042, '<NAME>', 7, 2, 5, 99]
        result = list(transform([headers, row]))
        self.assertEqual(len(result), 9)
        self.assertTrue(Atom('athlete', '<NAME>') in result)
        self.assertTrue(Atom('age', 42) in result)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

    def test_one_row_seven(self):
        row = ['Slovenia', 4042, '<NAME>', 7, 2, 5, 99]
        result = list(transform([headers, row]))
        self.assertEqual(len(result), 7)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

    def test_two_rows(self):
        rows = [ ['<NAME>', 42, 'Slovenia', 4042, '<NAME>', 7, 2, 5, 99],
                 ['<NAME>', 42, 'New Slovenia', 9088, '<NAME>', 0, 0, 16, 99] ]
        result = list(transform([headers] + rows))
        self.assertEqual(len(result), 14)
        self.assertTrue(Atom('athlete', '<NAME>') in result)
        self.assertTrue(Atom('age', 42) in result)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('country', 'New Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('year', 9088) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('golds', 0) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('silvers', 0) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('bronzes', 16) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

        


if __name__ == '__main__':
    unittest.main()

import unittest

from core import Atom
from rows2atoms import transform

headers = ['athlete', 'age', 'country', 'year', 'sport', 'golds', 'silvers', 'bronzes', 'total_medals']

class Rows2AtomsTests(unittest.TestCase):

    def test_empty(self):
        self.assertEqual(list(transform([headers])), [])

    def test_one_row_nine(self):
        row = ['<NAME>', 42, 'Slovenia', 4042, '<NAME>', 7, 2, 5, 99]
        result = list(transform([headers, row]))
        self.assertEqual(len(result), 9)
        self.assertTrue(Atom('athlete', '<NAME>') in result)
        self.assertTrue(Atom('age', 42) in result)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

    def test_one_row_seven(self):
        row = ['Slovenia', 4042, '<NAME>', 7, 2, 5, 99]
        result = list(transform([headers, row]))
        self.assertEqual(len(result), 7)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

    def test_two_rows(self):
        rows = [ ['<NAME>', 42, 'Slovenia', 4042, '<NAME>', 7, 2, 5, 99],
                 ['<NAME>', 42, 'New Slovenia', 9088, '<NAME>', 0, 0, 16, 99] ]
        result = list(transform([headers] + rows))
        self.assertEqual(len(result), 14)
        self.assertTrue(Atom('athlete', '<NAME>') in result)
        self.assertTrue(Atom('age', 42) in result)
        self.assertTrue(Atom('country', 'Slovenia') in result)
        self.assertTrue(Atom('country', 'New Slovenia') in result)
        self.assertTrue(Atom('year', 4042) in result)
        self.assertTrue(Atom('year', 9088) in result)
        self.assertTrue(Atom('sport', 'Nether Bowling') in result)
        self.assertTrue(Atom('golds', 7) in result)
        self.assertTrue(Atom('golds', 0) in result)
        self.assertTrue(Atom('silvers', 2) in result)
        self.assertTrue(Atom('silvers', 0) in result)
        self.assertTrue(Atom('bronzes', 5) in result)
        self.assertTrue(Atom('bronzes', 16) in result)
        self.assertTrue(Atom('total_medals', 99) in result)

        


if __name__ == '__main__':
    unittest.main()