Page MenuHomec4science

test_flood_fill.py
No OneTemporary

File Metadata

Created
Tue, Nov 19, 11:28

test_flood_fill.py

# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import print_function, division
import tamaas as tm
import numpy as np
def test_flood_fill2d(tamaas_fixture):
field = np.zeros((18, 18), np.bool)
# Cluster of permeter 18 area 13
field[2:4, 3:6] = True
field[4 , 4:6] = True # noqa
field[5 , 5 ] = True # noqa
field[3:5, 6:8] = True # noqa
# Cluster of perimeter 8 area 4
field[14:16, 3:5] = True
# Cluster of perimeter 20 area 11
field[9:11, 8:11 ] = True # noqa
field[7:9 , 9 ] = True # noqa
field[10 , 11:14] = True # noqa
# Cluster of perimeter 18 area 9
field[3:5, 14:16] = True
field[5:10, 15] = True
clusters = tm.FloodFill.getClusters(field, False)
# Dummy class for clusters
class dummy:
def __init__(self, area, perimeter):
self.area = area
self.perimeter = perimeter
# Solution
ref = [dummy(13, 18), dummy(9, 18), dummy(11, 20), dummy(4, 8)]
for x, y in zip(clusters, ref):
assert x.getArea() == y.area
assert x.getPerimeter() == y.perimeter
def test_flood_fill3d(tamaas_fixture):
field = np.zeros((5, 5, 5), np.bool)
field[2:4, 3, 1:3] = True
clusters = tm.FloodFill.getVolumes(field, False)
assert len(clusters) == 1
assert clusters[0].getArea() == 4

Event Timeline