Public Function IsGoodShiftLeft() As Boolean
' verify correct ShiftLeft returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "ShiftLeft03" with the name of your function to test
  If ShiftLeft03(1, -1) <> 0 Then Stop: fFailed = True
  If ShiftLeft03(1, 0) <> 1 Then Stop: fFailed = True
  If ShiftLeft03(1, 1) <> 2 Then Stop: fFailed = True
  If ShiftLeft03(1, 2) <> 4 Then Stop: fFailed = True
  If ShiftLeft03(1, 3) <> 8 Then Stop: fFailed = True
  If ShiftLeft03(1, 31) <> &H80000000 Then Stop: fFailed = True
  If ShiftLeft03(1, 33) <> 0 Then Stop: fFailed = True
  If ShiftLeft03(170, 1) <> 340 Then Stop: fFailed = True
  If ShiftLeft03(-170, 1) <> -340 Then Stop: fFailed = True
  If ShiftLeft03(255, 24) <> -16777216 Then Stop: fFailed = True
  If ShiftLeft03(&HFFFFFFFF, 1) <> -2 Then Stop: fFailed = True
  If ShiftLeft03(&HFFFFFFFF, 0) <> -1 Then Stop: fFailed = True
  
  ' well done
  IsGoodShiftLeft = Not fFailed
  
End Function


Public Function IsGoodShiftRight() As Boolean
' verify correct ShiftRight returns, rev 001 20011009
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "ShiftRight07" with the name of your function to test
  If ShiftRight07(8, 0) <> 8 Then Stop: fFailed = True
  If ShiftRight07(8, 1) <> 4 Then Stop: fFailed = True
  If ShiftRight07(8, 2) <> 2 Then Stop: fFailed = True
  If ShiftRight07(8, 3) <> 1 Then Stop: fFailed = True
  If ShiftRight07(8, 4) <> 0 Then Stop: fFailed = True
  If ShiftRight07(8, 33) <> 0 Then Stop: fFailed = True
  If ShiftRight07(170, 3) <> 21 Then Stop: fFailed = True
  If ShiftRight07(&HFFFFFFFF, 0) <> -1 Then Stop: fFailed = True
  
  ' new and correct:
  If ShiftRight07(-170, 3) <> -22 Then Stop: fFailed = True
  If ShiftRight07(&HFFFFFFFF, 1) <> -1 Then Stop: fFailed = True
  ' old and wrong!:
  ''If ShiftRight07(-170, 3) <> -21 Then Stop: fFailed = True
  ''If ShiftRight07(&HFFFFFFFF, 1) <> 0 Then Stop: fFailed = True
  
  If ShiftRight07(&HAAAAAAAA, 1) <> -715827883 Then Stop: fFailed = True
  If ShiftRight07(&HAAAAAAAA, 31) <> -1 Then Stop: fFailed = True
  If ShiftRight07(&H7FFFFFFF, 31) <> 0 Then Stop: fFailed = True
  
  ' handling illegal input values
  If ShiftRight07(8, -1) <> 0 Then Stop: fFailed = True
  
  ' well done
  IsGoodShiftRight = Not fFailed
  
End Function


Public Function IsGoodShiftRightZ() As Boolean
' verify correct ShiftRightZ returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "ShiftRightZ04" with the name of your function to test
  If ShiftRightZ04(8, -1) <> 0 Then Stop: fFailed = True
  If ShiftRightZ04(8, 0) <> 8 Then Stop: fFailed = True
  If ShiftRightZ04(8, 1) <> 4 Then Stop: fFailed = True
  If ShiftRightZ04(8, 2) <> 2 Then Stop: fFailed = True
  If ShiftRightZ04(8, 3) <> 1 Then Stop: fFailed = True
  If ShiftRightZ04(8, 4) <> 0 Then Stop: fFailed = True
  If ShiftRightZ04(8, 33) <> 0 Then Stop: fFailed = True
  If ShiftRightZ04(170, 3) <> 21 Then Stop: fFailed = True
  If ShiftRightZ04(-170, 3) <> 536870890 Then Stop: fFailed = True
  If ShiftRightZ04(&HFFFFFFFF, 1) <> 2147483647 Then Stop: fFailed = True
  If ShiftRightZ04(&HFFFFFFFF, 0) <> -1 Then Stop: fFailed = True
  
  ' well done
  IsGoodShiftRightZ = Not fFailed
  
End Function


Back to ShiftLeft