@@ -726,11 +726,78 @@ class Dummy(SubDomainSet):
726726
727727
728728class TestBorder :
729+ def test_exceptions (self ):
730+ """Test exceptions are raised for malformed specifications"""
731+ grid = Grid (shape = (5 ,))
732+
733+ with pytest .raises (ValueError ):
734+ _ = Border (grid , (1 , 1 ))
735+
736+ with pytest .raises (ValueError ):
737+ _ = Border (grid , ((1 , 1 , 1 ),))
738+
739+ @pytest .mark .parametrize ('corners' , ['nooverlap' , 'overlap' , 'nocorners' ])
740+ def test_uneven_border (self , corners ):
741+ """Test border specifications which vary by dimension"""
742+ shape = (6 , 8 )
743+ grid = Grid (shape = shape )
744+ x , y = grid .dimensions
745+
746+ border = Border (grid , (1 , (2 , 1 )), corners = corners )
747+
748+ f = Function (name = 'f' , grid = grid , dtype = np .int32 )
749+
750+ eq = Eq (f , f + 1 , subdomain = border )
751+
752+ Operator (eq )()
753+
754+ check = np .ones (shape )
755+ check [1 :- 1 , 2 :- 1 ] = 0
756+
757+ if corners == 'nocorners' :
758+ check [0 , :2 ] = 0
759+ check [- 1 , :2 ] = 0
760+ check [0 , - 1 ] = 0
761+ check [- 1 , - 1 ] = 0
762+ elif corners == 'overlap' :
763+ check [0 , :2 ] = 2
764+ check [- 1 , :2 ] = 2
765+ check [0 , - 1 ] = 2
766+ check [- 1 , - 1 ] = 2
767+
768+ assert np .all (f .data == check )
769+
770+ @pytest .mark .parametrize ('corners' , ['nooverlap' , 'overlap' , 'nocorners' ])
771+ def test_one_sided_border (self , corners ):
772+ """Test borders where a particular side is specified"""
773+ shape = (6 , 8 )
774+ grid = Grid (shape = shape )
775+ x , y = grid .dimensions
776+
777+ # border = Border(grid, 2, dims={x: x, y: 'right'})
778+ border = Border (grid , 1 , dims = {x : 'left' , y : 'right' }, corners = corners )
779+
780+ f = Function (name = 'f' , grid = grid , dtype = np .int32 )
781+
782+ eq = Eq (f , f + 1 , subdomain = border )
783+
784+ Operator (eq )()
785+
786+ check = np .zeros (shape )
787+ check [0 , :] = 1
788+ check [:, - 1 ] = 1
789+
790+ if corners == 'overlap' :
791+ check [0 , - 1 ] = 2
792+ elif corners == 'nocorners' :
793+ check [0 , 0 ] = 0
794+ check [0 , - 1 ] = 0
795+ check [- 1 , - 1 ] = 0
796+
797+ assert np .all (f .data == check )
798+
729799 def test_border_3d (self ):
730- """
731- Test the functionality of the Border class in higher dimensions.
732- Note that this class is also covered by doctests and examples.
733- """
800+ """Test the functionality of the Border class in higher dimensions"""
734801 grid = Grid (shape = (3 , 3 , 3 ))
735802
736803 border = Border (grid , 1 )
0 commit comments