<commit_before># -*- coding: utf-8 -*-

from future import standard_library

standard_library.install_aliases()
from builtins import range
import os
import unittest
import io
from quantized_mesh_tile.terrain import TerrainTile
from quantized_mesh_tile.topology import TerrainTopology
from quantized_mesh_tile.global_geodetic import GlobalGeodetic


class TestTerrainTile(unittest.TestCase):
    def setUp(self):
        self.tmpfile = 'tests/data/temp.terrain'

    def tearDown(self):
        if os.path.exists(self.tmpfile):
            os.remove(self.tmpfile)

    def testReaderWriter(self):
        '''
        Circle jerk testing.
        We read the file with our reader
        We write this data with our writer to a temporary file
        We read this temporary file
        We compare the results
        '''
        x = 533
        y = 383
        z = 9
        geodetic = GlobalGeodetic(True)
        [minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z)

        ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter.fromFile('tests/data/%s_%s_%s.terrain' % (z, x, y))
        ter.toFile(self.tmpfile)
        self.assertIsInstance(ter.__repr__(), str)

        ter2 = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter2.fromFile(self.tmpfile)
        self.assertIsInstance(ter2.__repr__(), str)

        # check headers
        self.assertGreater(len(ter.header), 0)
        self.assertEqual(len(ter.header), len(ter2.header))
        self.assertEqual(len(ter.header), len(TerrainTile.quantizedMeshHeader))
        for k, v in ter.header.items():
            self.assertEqual(v, ter2.header[k], 'For k = ' + k)

        # check vertices
        self.assertGreater(len(ter.u), 0)
        self.assertGreater(len(ter.v), 0)
        self.assertGreater(len(ter.h), 0)
        self.assertEqual(len(ter.u), len(ter2.u))
        self.assertEqual(len(ter.v), len(ter2.v))
        self.assertEqual(len(ter.h), len(ter2.h))
        for i, v in enumerate(ter.u):
            self.assertEqual(v, ter2.u[i])
        for i, v in enumerate(ter.v):
            self.assertEqual(v, ter2.v[i])
        for i, v in enumerate(ter.h):
            self.assertEqual(v, ter2.h[i])
        self.assertEqual(
            len(ter.getVerticesCoordinates()),
            len(ter2.getVerticesCoordinates())
        )

        # check indices
        self.assertGreater(len(ter.indices), 0)
        self.assertEqual(len(ter.indices), len(ter2.indices))
        for i, v in enumerate(ter.indices):
            self.assertEqual(v, ter2.indices[i], i)

        # check edges
        self.assertGreater(len(ter.westI), 0)
        self.assertEqual(len(ter.westI), len(ter2.westI))
        for i, v in enumerate(ter.westI):
            self.assertEqual(v, ter2.westI[i], i)

        self.assertGreater(len(ter.southI), 0)
        self.assertEqual(len(ter.southI), len(ter2.southI))
        for i, v in enumerate(ter.southI):
            self.assertEqual(v, ter2.southI[i], i)

        self.assertGreater(len(ter.eastI), 0)
        self.assertEqual(len(ter.eastI), len(ter2.eastI))
        for i, v in enumerate(ter.eastI):
            self.assertEqual(v, ter2.eastI[i], i)

        self.assertGreater(len(ter.northI), 0)
        self.assertEqual(len(ter.northI), len(ter2.northI))
        for i, v in enumerate(ter.northI):
            self.assertEqual(v, ter2.northI[i], i)

        self.assertEqual(ter2.getContentType(),
                         'application/vnd.quantized-mesh')

    def testWatermaskOnlyReader(self):
        z = 9
        x = 769
        y = 319
        geodetic = GlobalGeodetic(True)
        [minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z)

        ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter.fromFile('tests/data/%s_%s_%s_watermask.terrain' % (z, x, y),
                     hasWatermask=True)
<commit_msg>Control the number of indices on the edge of the tile<commit_after># -*- coding: utf-8 -*-

from future import standard_library

standard_library.install_aliases()
from builtins import range
import os
import unittest
import io
from quantized_mesh_tile.terrain import TerrainTile
from quantized_mesh_tile.topology import TerrainTopology
from quantized_mesh_tile.global_geodetic import GlobalGeodetic


class TestTerrainTile(unittest.TestCase):
    def setUp(self):
        self.tmpfile = 'tests/data/temp.terrain'

    def tearDown(self):
        if os.path.exists(self.tmpfile):
            os.remove(self.tmpfile)

    def testReaderWriter(self):
        '''
        Circle jerk testing.
        We read the file with our reader
        We write this data with our writer to a temporary file
        We read this temporary file
        We compare the results
        '''
        x = 533
        y = 383
        z = 9
        geodetic = GlobalGeodetic(True)
        [minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z)

        ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter.fromFile('tests/data/%s_%s_%s.terrain' % (z, x, y))
        ter.toFile(self.tmpfile)
        self.assertIsInstance(ter.__repr__(), str)

        ter2 = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter2.fromFile(self.tmpfile)
        self.assertIsInstance(ter2.__repr__(), str)

        # check headers
        self.assertGreater(len(ter.header), 0)
        self.assertEqual(len(ter.header), len(ter2.header))
        self.assertEqual(len(ter.header), len(TerrainTile.quantizedMeshHeader))
        for k, v in ter.header.items():
            self.assertEqual(v, ter2.header[k], 'For k = ' + k)

        # check vertices
        self.assertGreater(len(ter.u), 0)
        self.assertGreater(len(ter.v), 0)
        self.assertGreater(len(ter.h), 0)
        self.assertEqual(len(ter.u), len(ter2.u))
        self.assertEqual(len(ter.v), len(ter2.v))
        self.assertEqual(len(ter.h), len(ter2.h))
        for i, v in enumerate(ter.u):
            self.assertEqual(v, ter2.u[i])
        for i, v in enumerate(ter.v):
            self.assertEqual(v, ter2.v[i])
        for i, v in enumerate(ter.h):
            self.assertEqual(v, ter2.h[i])
        self.assertEqual(
            len(ter.getVerticesCoordinates()),
            len(ter2.getVerticesCoordinates())
        )

        # check indices
        self.assertGreater(len(ter.indices), 0)
        self.assertEqual(len(ter.indices), len(ter2.indices))
        for i, v in enumerate(ter.indices):
            self.assertEqual(v, ter2.indices[i], i)

        # check edges
        self.assertGreater(len(ter.westI), 0)
        self.assertEqual(len(ter.westI), len(ter2.westI))
        for i, v in enumerate(ter.westI):
            self.assertEqual(v, ter2.westI[i], i)

        self.assertGreater(len(ter.southI), 0)
        self.assertEqual(len(ter.southI), len(ter2.southI))
        for i, v in enumerate(ter.southI):
            self.assertEqual(v, ter2.southI[i], i)

        self.assertGreater(len(ter.eastI), 0)
        self.assertEqual(len(ter.eastI), len(ter2.eastI))
        for i, v in enumerate(ter.eastI):
            self.assertEqual(v, ter2.eastI[i], i)

        self.assertGreater(len(ter.northI), 0)
        self.assertEqual(len(ter.northI), len(ter2.northI))
        for i, v in enumerate(ter.northI):
            self.assertEqual(v, ter2.northI[i], i)

        # check vertice sitting on the edge
        # we already know the number of indices on the edges
        self.assertEqual(len(ter2.westI), 30)
        self.assertEqual(len(ter2.eastI), 10)
        self.assertEqual(len(ter2.southI), 14)
        self.assertEqual(len(ter2.northI), 25)

        self.assertEqual(ter2.getContentType(),
                         'application/vnd.quantized-mesh')

    def testWatermaskOnlyReader(self):
        z = 9
        x = 769
        y = 319
        geodetic = GlobalGeodetic(True)
        [minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z)

        ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
        ter.fromFile('tests/data/%s_%s_%s_watermask.terrain' % (z, x, y),
                     hasWatermask=True)

{'fraction_non_alphanumeric': 0.12444553967471661, 'fraction_numerical': 0.013060620995564317, 'mean_word_length': 2.4335871404399323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256561', 'n_tokens_mistral': 2789, 'n_tokens_neox': 2657, 'n_words': 548}