import numpy as np

from numpy.testing import assert_array_equal
from nose.tools import raises, assert_true

from landlab.grid.structured_quad.nodes import status_with_perimeter_as_boundary
from landlab.grid.structured_quad.links import active_link_ids

from landlab.grid.base import CORE_NODE, FIXED_VALUE_BOUNDARY, CLOSED_BOUNDARY


def test_active_links_ids():
    status = np.empty((4, 5), dtype=int)
    status.fill(CLOSED_BOUNDARY)
    status[1, 2] = status[1, 3] = status[2, 2] = status[2, 3] = CORE_NODE

    link_ids = active_link_ids((4, 5), status)
    assert_array_equal(link_ids, [7, 8, 21, 25])
    assert_true(str(link_ids.dtype).startswith('int'))


def test_active_links_with_edge_boundaries():
    status = status_with_perimeter_as_boundary((3, 4))
    link_ids = active_link_ids((3, 4), status)
    assert_array_equal(link_ids, [1, 2, 5, 6, 11, 12, 13])
    assert_true(str(link_ids.dtype).startswith('int'))


@raises(ValueError)
def test_active_link_ids_with_shape_mismatch():
    active_link_ids((3, 4), np.zeros(3))

@@ -96,20 +96,21 @@
  assert_
-true
+equal
 %0A%0Afrom l
@@ -610,32 +610,29 @@
 %0A    assert_
-true(str
+equal
 (link_ids.dt
@@ -634,35 +634,24 @@
 ds.dtype
-).startswith('
+, np.
 int
-')
 )%0A%0A%0Adef 
@@ -868,16 +868,13 @@
 ert_
-true(str
+equal
 (lin
@@ -888,27 +888,16 @@
 type
-).startswith('
+, np.
 int
-')
 )%0A%0A%0A

Test of index arrays of type int.