@@ -13,7 +13,7 @@ class SkylineProblemTest {
1313 @ Test
1414 void testSingleBuildingSkyline () {
1515 SkylineProblem skylineProblem = new SkylineProblem ();
16- skylineProblem .building = new SkylineProblem . Building [ 1 ] ;
16+ skylineProblem .setBuilding ( 1 ) ;
1717 skylineProblem .add (2 , 10 , 9 );
1818
1919 List <SkylineProblem .Skyline > result = skylineProblem .findSkyline (0 , 0 );
@@ -24,7 +24,7 @@ void testSingleBuildingSkyline() {
2424 @ Test
2525 void testTwoBuildingsSkyline () {
2626 SkylineProblem skylineProblem = new SkylineProblem ();
27- skylineProblem .building = new SkylineProblem . Building [ 2 ] ;
27+ skylineProblem .setBuilding ( 2 ) ;
2828 skylineProblem .add (1 , 11 , 5 );
2929 skylineProblem .add (2 , 6 , 7 );
3030
@@ -48,7 +48,7 @@ void testMergeSkyline() {
4848 @ Test
4949 void testMultipleBuildingsSkyline () {
5050 SkylineProblem skylineProblem = new SkylineProblem ();
51- skylineProblem .building = new SkylineProblem . Building [ 3 ] ;
51+ skylineProblem .setBuilding ( 3 ) ;
5252 skylineProblem .add (1 , 10 , 5 );
5353 skylineProblem .add (2 , 15 , 7 );
5454 skylineProblem .add (3 , 12 , 9 );
@@ -65,15 +65,15 @@ void testAddBuildingInvalidCases() {
6565 Exception ex = assertThrows (IllegalStateException .class , () -> skylineProblem .add (1 , 2 , 3 ));
6666 assertTrue (ex .getMessage ().contains ("not initialized" ));
6767
68- skylineProblem .building = new SkylineProblem . Building [ 1 ] ;
68+ skylineProblem .setBuilding ( 1 ) ;
6969 skylineProblem .add (1 , 2 , 3 );
7070 // Array full
7171 Exception ex2 = assertThrows (IllegalStateException .class , () -> skylineProblem .add (4 , 5 , 6 ));
7272 assertTrue (ex2 .getMessage ().contains ("full" ));
7373
7474 // Invalid left >= right
7575 SkylineProblem skylineProblem2 = new SkylineProblem ();
76- skylineProblem2 .building = new SkylineProblem . Building [ 1 ] ;
76+ skylineProblem2 .setBuilding ( 1 ) ;
7777 Exception ex3 = assertThrows (IllegalArgumentException .class , () -> skylineProblem2 .add (5 , 2 , 2 ));
7878 assertTrue (ex3 .getMessage ().contains ("Left coordinate" ));
7979
@@ -89,7 +89,7 @@ void testFindSkylineInvalidCases() {
8989 Exception ex = assertThrows (IllegalArgumentException .class , () -> skylineProblem .findSkyline (0 , 0 ));
9090 assertTrue (ex .getMessage ().contains ("not initialized" ));
9191
92- skylineProblem .building = new SkylineProblem . Building [ 2 ] ;
92+ skylineProblem .setBuilding ( 2 ) ;
9393 skylineProblem .count = 1 ;
9494 Exception ex2 = assertThrows (IllegalArgumentException .class , () -> skylineProblem .findSkyline (0 , 1 ));
9595 assertTrue (ex2 .getMessage ().contains ("Invalid start or end index" ));
@@ -98,18 +98,8 @@ void testFindSkylineInvalidCases() {
9898 @ Test
9999 void testMergeSkylineNullCases () {
100100 SkylineProblem skylineProblem = new SkylineProblem ();
101- Exception ex1 = assertThrows (NullPointerException .class , new org .junit .jupiter .api .function .Executable () {
102- @ Override
103- public void execute () {
104- skylineProblem .mergeSkyline (null , List .of ());
105- }
106- });
107- Exception ex2 = assertThrows (NullPointerException .class , new org .junit .jupiter .api .function .Executable () {
108- @ Override
109- public void execute () {
110- skylineProblem .mergeSkyline (List .of (), null );
111- }
112- });
101+ Exception ex1 = assertThrows (NullPointerException .class , () -> skylineProblem .mergeSkyline (null , List .of ()));
102+ Exception ex2 = assertThrows (NullPointerException .class , () -> skylineProblem .mergeSkyline (List .of (), null ));
113103 assertTrue (ex1 .getMessage ().contains ("sky1" ));
114104 assertTrue (ex2 .getMessage ().contains ("sky2" ));
115105 }
0 commit comments