= #JxnPortable/docs/programmer_examples/demos/PrimitiveParameterCast_boolean_UnitTest.jxn

#ifndef noFiles
! run as single file
resetAll = true
#else
! run as part of a set of multiple files
noFiles = noFiles + 1
resetAll = false
#endif
!
#ifndef ut
@Date()
ut = @JxnUnitTest();
#endif
#ifndef ut_ok
ut_ok = @JxnUnitTest();
#endif
!
! reset debug to default (abort on unexpected exception => must be recognized and fixed e.g. using $this.test( "..." ) )
oldDebug = $this.setDebug true


#function $test( $1 )
JxnPrimitiveWrapper.setPluggable $1
JxnPrimitiveWrapper.getParameterCast()
!
d8f = 0.
d8t = 1.  ! or any value != 0.0
f4f = JxnCast.toFloat 0.
f4t = JxnCast.toFloat 1.  ! or any value != 0.0
i8f = JxnCast.toLong 0
i8t = JxnCast.toLong 1  ! or any value != 0
i4f = 0
i4t = 1  ! or any value != 0
i2f = JxnCast.toShort 0
i2t = JxnCast.toShort 1  ! or any value != 0
by1f = JxnCast.toByte 0
by1t = JxnCast.toByte 1  ! or any value != 0
ch2f = 'f'  ! or any value except:
ch2t = 't'  ! or '1' or 'T' or 'y' or 'Y'
ut.assertEquals(    "char:t",   JxnParameterCheck.whatIs +ch2t )
ut_ok.assertEquals( "int:-116", JxnParameterCheck.whatIs -ch2t )
!
$exp = "invokeMethod: JxnParameterCheck.testBoolean( double ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( d8f )" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( d8t )" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( float ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( f4f )" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( f4t )" )
#if $1.equals "Safe"
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean(  i8f ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( -i8t ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( +i8t ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean(  i4f ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( -i4t ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( +i4t ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean(  i2f ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( -i2t ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( +i2t ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean(  by1f ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( -by1t ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( +by1t ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean(  ch2f ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( -ch2t ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( +ch2t ) )
#else
$exp = "invokeMethod: JxnParameterCheck.testBoolean( long ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean i8f" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( int ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean i4t" ) ) )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( short ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean i2f" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( byte ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean by1t" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( char ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean ch2t" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean ch2f" )
#endif
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -d8t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +d8t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  d8f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -f4t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +f4t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  f4f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -i8t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +i8t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  i8f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -i4t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +i4t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  i4f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -i2t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +i2t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  i2f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -by1t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +by1t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  by1f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( -ch2t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( +ch2t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean(  ch2f ) ) )
!
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -d8t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +d8t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  d8f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -f4t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +f4t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  f4f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -i8t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +i8t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  i8f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -i4t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +i4t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  i4f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -i2t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +i2t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  i2f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -by1t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +by1t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  by1f ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( -ch2t ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( +ch2t ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test(  ch2f ) ) )
!
$exp = "invokeMethod: JxnParameterCheck.testBoolean( null ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( null )" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( java.lang.String ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( \"\" )" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( \"abc\" )" )
$exp = "invokeMethod: JxnCast.toBoolean( null ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( JxnCast.toBoolean( null ) )" )
$exp = "invokeMethod: JxnCast.toBoolean( java.lang.String ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( JxnCast.toBoolean( \"\" ) )" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean( JxnCast.toBoolean( \"abc\" ) )" )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( if_test( null ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( "" ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( if_test( "abc" ) ) )
!
#if $1.equals "Safe"
ut.assertEquals( "double:1.0", JxnParameterCheck.testDouble( true ) )
ut.assertEquals( "double:0.0", JxnParameterCheck.testDouble( false ) )
ut.assertEquals( "float:1.0",  JxnParameterCheck.testFloat( true ) )
ut.assertEquals( "float:0.0",  JxnParameterCheck.testFloat( false ) )
ut.assertEquals( "long:1",     JxnParameterCheck.testLong( true ) )
ut.assertEquals( "long:0",     JxnParameterCheck.testLong( false ) )
ut.assertEquals( "int:1",      JxnParameterCheck.testInt( true ) )
ut.assertEquals( "int:0",      JxnParameterCheck.testInt( false ) )
ut.assertEquals( "short:1",    JxnParameterCheck.testShort( true ) )
ut.assertEquals( "short:0",    JxnParameterCheck.testShort( false ) )
ut.assertEquals( "byte:1",     JxnParameterCheck.testByte( true ) )
ut.assertEquals( "byte:0",     JxnParameterCheck.testByte( false ) )
ut.assertEquals( "char:1",     JxnParameterCheck.testChar( true ) )
ut.assertEquals( "char:0",     JxnParameterCheck.testChar( false ) )
#else
$exp = "invokeMethod: JxnParameterCheck.testDouble( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testDouble true" )
$exp = "invokeMethod: JxnParameterCheck.testFloat( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testFloat false" )
$exp = "invokeMethod: JxnParameterCheck.testLong( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testLong true" )
$exp = "invokeMethod: JxnParameterCheck.testInt( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testInt false" )
$exp = "invokeMethod: JxnParameterCheck.testShort( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testShort true" )
$exp = "invokeMethod: JxnParameterCheck.testByte( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testByte false" )
$exp = "invokeMethod: JxnParameterCheck.testChar( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar true" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar false" )
#endif
ut.assertEquals( "double:0.0", JxnParameterCheck.testDouble( JxnCast.toDouble( false ) ) )
ut.assertEquals( "float:1.0",  JxnParameterCheck.testFloat(  JxnCast.toFloat( true ) ) )
ut.assertEquals( "long:0",     JxnParameterCheck.testLong(   JxnCast.toLong( false ) ) )
ut.assertEquals( "int:1",      JxnParameterCheck.testInt(    JxnCast.toInt( true ) ) )
ut.assertEquals( "short:0",    JxnParameterCheck.testShort(  JxnCast.toShort( false ) ) )
ut.assertEquals( "byte:1",     JxnParameterCheck.testByte(   JxnCast.toByte( true ) ) )
ut.assertEquals( "char:0",     JxnParameterCheck.testChar(   JxnCast.toChar( false ) ) )
ut.assertEquals( "char:1",     JxnParameterCheck.testChar(   JxnCast.toChar( true ) ) )
!
ia = { 0 : 127 }
@String JxnCast.toChar ia[32:]
ut.assertEquals( "1TYty", squeeze @String JxnCast.toChar sw( JxnCast.toBoolean JxnCast.toChar ia, ia, 32 ) )
!
#return
#endfunction
$test.setDebug 1


#function if_test( cond )
   #if cond
       #return true
   #endif
   #return false
#endfunction


$test "Safe"
$test "Java"

JxnPrimitiveWrapper.setPluggable ""


! >>> keep/move this block at/to end of file >>>
$this.setDebug oldDebug
!
ut.summary()
ut_ok.summary()
JxnUnitTestFailureExpected.summaryAll( resetAll )
! <<< keep/move this block at/to end of file <<<