Skip to content

Commit

Permalink
Add tests/test_indextype.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Jul 4, 2023
1 parent 6f88f79 commit a861ce7
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/test_indextype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr


@pytest.mark.skipif(amr.Config.spacedim != 1, reason="Requires AMREX_SPACEDIM = 1")
def test_indextype_1d():
obj = amr.IndexType(amr.IndexType.CellIndex.NODE)
assert obj.node_centered()
assert not obj.cell_centered()
with pytest.raises(IndexError):
obj[-2]
with pytest.raises(IndexError):
obj[1]


@pytest.mark.skipif(amr.Config.spacedim != 2, reason="Requires AMREX_SPACEDIM = 2")
def test_indextype_2d():
obj = amr.IndexType(amr.IndexType.CellIndex.NODE, amr.IndexType.CellIndex.CELL)
assert obj.node_centered(0)
assert obj.cell_centered(1)
assert obj.node_centered(-2)
assert obj.cell_centered(-1)

with pytest.raises(IndexError):
obj[-3]
with pytest.raises(IndexError):
obj[2]


@pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3")
def test_indextype_3d():
obj = amr.IndexType(amr.IndexType.CellIndex.NODE, amr.IndexType.CellIndex.CELL, amr.IndexType.CellIndex.NODE)

# Check indexing
assert obj.node_centered(0)
assert obj.cell_centered(1)
assert obj.node_centered(2)
assert obj.node_centered(-3)
assert obj.cell_centered(-2)
assert obj.node_centered(-1)
with pytest.raises(IndexError):
obj[-4]
with pytest.raises(IndexError):
obj[3]

# Check methods
obj.set(1)
assert obj.node_centered()
obj.unset(1)
assert not obj.node_centered()


def test_indextype_static():
cell = amr.IndexType.cell_type();
for i in range(amr.Config.spacedim):
assert not cell[i]

node = amr.IndexType.node_type();
for i in range(amr.Config.spacedim):
assert node[i]

assert cell == amr.IndexType.cell_type()
assert node == amr.IndexType.node_type()
assert cell < node


def test_indextype_conversions():
node = amr.IndexType.node_type();
assert node.ix_type() == amr.IntVect(1)
assert node.to_IntVect() == amr.IntVect(1)

0 comments on commit a861ce7

Please sign in to comment.