99 Turn ,
1010 reverseConnection ,
1111 onFloor ,
12+ isValidBuilding ,
13+ assertValidBuilding ,
1214} from "." ;
1315
1416const { RIGHT , LEFT , BACK , FRONT } = Direction ;
@@ -300,61 +302,72 @@ describe("Building.validity", () => {
300302 it ( "marks valid buildings correctly" , ( ) => {
301303 const valid = expect . objectContaining ( { valid : true } ) ;
302304
303- expect (
304- new Building ( [ new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) ] ) ] ) . validity
305- ) . toEqual ( valid ) ;
305+ const b = new Building ( [ new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) ] ) ] ) ;
306+ expect ( isValidBuilding ( b ) ) . toEqual ( valid ) ;
307+ assertValidBuilding ( b ) ;
306308
307309 expect (
308- new Building ( [
309- new Hallway ( [
310- new Room ( "a" ) ,
311- new Room ( "b" ) ,
312- new Turn ( RIGHT ) ,
313- new Fork ( LEFT , "a" , "" ) ,
314- ] ) ,
315- ] ) . validity
310+ isValidBuilding (
311+ new Building ( [
312+ new Hallway ( [
313+ new Room ( "a" ) ,
314+ new Room ( "b" ) ,
315+ new Turn ( RIGHT ) ,
316+ new Fork ( LEFT , "a" , "" ) ,
317+ ] ) ,
318+ ] )
319+ )
316320 ) . toEqual ( valid ) ;
317321
318322 expect (
319- new Building ( [
320- new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
321- new Hallway ( [
322- new Room ( "z" ) ,
323- new Fork ( RIGHT , reverseConnection ( "a" ) , "" ) ,
324- ] ) ,
325- ] ) . validity
323+ isValidBuilding (
324+ new Building ( [
325+ new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
326+ new Hallway ( [
327+ new Room ( "z" ) ,
328+ new Fork ( RIGHT , reverseConnection ( "a" ) , "" ) ,
329+ ] ) ,
330+ ] )
331+ )
326332 ) . toEqual ( valid ) ;
327333
328334 expect (
329- new Building ( [
330- new Hallway ( [
331- new Room ( "a" ) ,
332- new Room ( "b" ) ,
333- new Stairs ( LEFT , onFloor ( "a" , 2 ) ) ,
334- ] ) ,
335- new Hallway ( [ new Room ( "z" ) , new Stairs ( RIGHT , onFloor ( "a" , 1 ) ) ] ) ,
336- ] ) . validity
335+ isValidBuilding (
336+ new Building ( [
337+ new Hallway ( [
338+ new Room ( "a" ) ,
339+ new Room ( "b" ) ,
340+ new Stairs ( LEFT , onFloor ( "a" , 2 ) ) ,
341+ ] ) ,
342+ new Hallway ( [ new Room ( "z" ) , new Stairs ( RIGHT , onFloor ( "a" , 1 ) ) ] ) ,
343+ ] )
344+ )
337345 ) . toEqual ( valid ) ;
338346 } ) ;
339347
340348 it ( "marks buildings with duplicated names as invalid" , ( ) => {
341- expect (
342- new Building ( [ new Hallway ( [ new Room ( "a" ) , new Room ( "a" ) ] ) ] ) . validity
343- ) . toEqual ( {
349+ const b = new Building ( [ new Hallway ( [ new Room ( "a" ) , new Room ( "a" ) ] ) ] ) ;
350+
351+ expect ( isValidBuilding ( b ) ) . toEqual ( {
344352 valid : false ,
345353 reason : "There's more than one room with the name 'a'" ,
346354 connectedSections : [ ] ,
347355 } ) ;
356+ expect ( ( ) => {
357+ assertValidBuilding ( b ) ;
358+ } ) . toThrow ( "There's more than one room with the name 'a'" ) ;
348359
349360 expect (
350- new Building ( [
351- new Hallway ( [
352- new Room ( "a" ) ,
353- new Room ( "b" ) ,
354- new Stairs ( LEFT , onFloor ( "c" , 4 ) ) ,
355- ] ) ,
356- new Hallway ( [ new Room ( "a" ) , new Stairs ( RIGHT , onFloor ( "b" , 1 ) ) ] ) ,
357- ] ) . validity
361+ isValidBuilding (
362+ new Building ( [
363+ new Hallway ( [
364+ new Room ( "a" ) ,
365+ new Room ( "b" ) ,
366+ new Stairs ( LEFT , onFloor ( "c" , 4 ) ) ,
367+ ] ) ,
368+ new Hallway ( [ new Room ( "a" ) , new Stairs ( RIGHT , onFloor ( "b" , 1 ) ) ] ) ,
369+ ] )
370+ )
358371 ) . toEqual (
359372 expect . objectContaining ( {
360373 valid : false ,
@@ -365,14 +378,16 @@ describe("Building.validity", () => {
365378
366379 it ( "marks buildings with negative weights as invalid" , ( ) => {
367380 expect (
368- new Building ( [
369- new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
370- new Hallway ( [
371- new Fork ( RIGHT , "f" , "" ) ,
372- new Room ( "z" ) ,
373- new Fork ( RIGHT , reverseConnection ( "a" ) , "" , - 2 ) ,
374- ] ) ,
375- ] ) . validity
381+ isValidBuilding (
382+ new Building ( [
383+ new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
384+ new Hallway ( [
385+ new Fork ( RIGHT , "f" , "" ) ,
386+ new Room ( "z" ) ,
387+ new Fork ( RIGHT , reverseConnection ( "a" ) , "" , - 2 ) ,
388+ ] ) ,
389+ ] )
390+ )
376391 ) . toEqual (
377392 expect . objectContaining ( {
378393 valid : false ,
@@ -383,15 +398,17 @@ describe("Building.validity", () => {
383398
384399 it ( "marks buildings with no nodes in a Hallway as invalid" , ( ) => {
385400 expect (
386- new Building ( [
387- new Hallway ( [
388- new Room ( "a" ) ,
389- new Room ( "b" ) ,
390- new Fork ( LEFT , reverseConnection ( "b" ) , "" ) ,
391- ] ) ,
392- new Hallway ( [ new Room ( "z" ) , new Fork ( RIGHT , "b" , "" ) ] ) ,
393- new Hallway ( [ new Room ( "c" ) , new Room ( "d" ) ] ) ,
394- ] ) . validity
401+ isValidBuilding (
402+ new Building ( [
403+ new Hallway ( [
404+ new Room ( "a" ) ,
405+ new Room ( "b" ) ,
406+ new Fork ( LEFT , reverseConnection ( "b" ) , "" ) ,
407+ ] ) ,
408+ new Hallway ( [ new Room ( "z" ) , new Fork ( RIGHT , "b" , "" ) ] ) ,
409+ new Hallway ( [ new Room ( "c" ) , new Room ( "d" ) ] ) ,
410+ ] )
411+ )
395412 ) . toEqual (
396413 expect . objectContaining ( {
397414 valid : false ,
@@ -402,19 +419,21 @@ describe("Building.validity", () => {
402419
403420 it ( "marks buildings with disconnected graphs as invalid" , ( ) => {
404421 expect (
405- new Building ( [
406- new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
407- new Hallway ( [
408- new Room ( "z" ) ,
409- new Fork ( RIGHT , reverseConnection ( "b" ) , "" ) ,
410- ] ) ,
411- new Hallway ( [ new Room ( "c" ) , new Fork ( RIGHT , "8" , "" ) ] ) ,
412- ] ) . validity
422+ isValidBuilding (
423+ new Building ( [
424+ new Hallway ( [ new Room ( "a" ) , new Room ( "b" ) , new Fork ( LEFT , "a" , "" ) ] ) ,
425+ new Hallway ( [
426+ new Room ( "z" ) ,
427+ new Fork ( RIGHT , reverseConnection ( "b" ) , "" ) ,
428+ ] ) ,
429+ new Hallway ( [ new Room ( "c" ) , new Fork ( RIGHT , "8" , "" ) ] ) ,
430+ ] )
431+ )
413432 ) . toEqual (
414433 expect . objectContaining ( {
415434 valid : false ,
416435 reason :
417- "Not all nodes are connected; see building.validity. connectedSections to find which node groups are separated" ,
436+ "Not all nodes are connected; see isValidBuilding( building). connectedSections to find which node groups are separated. " ,
418437 } )
419438 ) ;
420439 } ) ;
0 commit comments