Public Type HSL
  Hue         As Long
  Saturation  As Long
  Luminance   As Long
End Type

Public Function IsGoodRGBToHSL() As Boolean
' verify correct RGBtoHSL returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "RGBtoHSL02" with the name of your function to test
  If HSLAsString(RGBToHSL02(RGB(0, 0, 0))) <> "0,0,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(128, 128, 128))) <> "0,0,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(255, 255, 255))) <> "0,0,100" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL02(RGB(1, 0, 0))) <> "0,100,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(0, 1, 0))) <> "120,100,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(0, 0, 1))) <> "240,100,0" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL02(RGB(2, 0, 0))) <> "0,100,1" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(4, 0, 0))) <> "0,100,2" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(128, 0, 0))) <> "0,100,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(252, 0, 0))) <> "0,100,99" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(254, 0, 0))) <> "0,100,100" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(255, 0, 0))) <> "0,100,100" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL02(RGB(0, 255, 255))) <> "180,100,100" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(255, 0, 255))) <> "300,100,100" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(255, 255, 0))) <> "60,100,100" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL02(RGB(160, 176, 184))) <> "200,13,72" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL02(RGB(126, 148, 160))) <> "201,21,63" Then Stop: fFailed = True

  ' not a legal RGBValue, but it could happen in real life
  If HSLAsString(RGBToHSL03(&HFF000000 + RGB(126, 148, 160))) <> "201,21,63" Then Stop: fFailed = True  
  
  ' well done
  IsGoodRGBToHSL = Not fFailed
  
End Function

Public Function IsGoodRGBToHSL2() As Boolean
' verify correct RGBToHSL2 returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "RGBToHSL201" with the name of your function to test
  If HSLAsString(RGBToHSL201(RGB(0, 0, 0))) <> "0,0,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(128, 128, 128))) <> "0,0,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(255, 255, 255))) <> "0,0,100" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL201(RGB(1, 0, 0))) <> "0,100,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(0, 1, 0))) <> "120,100,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(0, 0, 1))) <> "240,100,0" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL201(RGB(2, 0, 0))) <> "0,100,0" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(4, 0, 0))) <> "0,100,1" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(128, 0, 0))) <> "0,100,25" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(252, 0, 0))) <> "0,100,49" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(254, 0, 0))) <> "0,100,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(255, 0, 0))) <> "0,100,50" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL201(RGB(0, 255, 255))) <> "180,100,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(255, 0, 255))) <> "300,100,50" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(255, 255, 0))) <> "60,100,50" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL201(RGB(160, 176, 184))) <> "200,14,67" Then Stop: fFailed = True
  If HSLAsString(RGBToHSL201(RGB(126, 148, 160))) <> "201,15,56" Then Stop: fFailed = True
  
  If HSLAsString(RGBToHSL201(RGB(96, 32, 32))) <> "0,50,25" Then Stop: fFailed = True
  
  ' not a legal RGBValue, but it could happen in real life
  If HSLAsString(RGBToHSL201(&HFF000000 + RGB(126, 148, 160))) <> "201,15,56" Then Stop: fFailed = True
  
  ' well done
  IsGoodRGBToHSL2 = Not fFailed
  
End Function

Public Function HSLAsString(uHSL As HSL) As String
  HSLAsString = uHSL.Hue & "," & uHSL.Saturation & "," & uHSL.Luminance
End Function


Back to RGBToHSL