Public Function IsGoodHSLToRGB() As Boolean
' verify correct RGBtoHSL returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' replace "HSLToRGB01" with the name of your function to test
  If RGBAsString(HSLToRGB01(0, 0, 0)) <> "0,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(0, 0, 50)) <> "128,128,128" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(0, 0, 100)) <> "255,255,255" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB01(0, 100, 1)) <> "3,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(120, 100, 1)) <> "0,3,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(240, 100, 1)) <> "0,0,3" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB01(0, 100, 50)) <> "128,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(0, 100, 99)) <> "252,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(0, 100, 100)) <> "255,0,0" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB01(180, 100, 100)) <> "0,255,255" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(300, 100, 100)) <> "255,0,255" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(60, 100, 100)) <> "255,255,0" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB01(200, 13, 72)) <> "160,176,184" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB01(201, 21, 63)) <> "127,149,161" Then Stop: fFailed = True
  
  ' validate check
  If RGBAsString(HSLToRGB01(480, 150, 150, True)) <> "0,255,0" Then Stop: fFailed = True
  
  ' well done
  IsGoodHSLToRGB = Not fFailed
  
End Function

Public Function IsGoodHSL2ToRGB(Optional fExact As Boolean) As Boolean
' verify correct HSLToRGB2 returns
' returns True if all tests are passed
  Dim fFailed As Boolean
  
  ' compare with known to be exact version
  Dim i As Long, H&, S&, L&
  S = 25: L = 50
  For i = 0 To 255
    If HSLToRGB205(i, S, L) <> HSLToRGB204(i, S, L) Then
      Debug.Print i
      Debug.Print "Is:", RGBAsString(HSLToRGB205(i, S, L))
      Debug.Print "Should:", RGBAsString(HSLToRGB204(i, S, L))
      fFailed = True
      Stop
    End If
  Next
  ' exactness
  If RGBAsString(HSLToRGB205(14, 25, 50)) <> "159,111,96" Then Stop: fFailed = True

  IsGoodHSL2ToRGB = Not fFailed
  ''Exit Function
  
  
  ' replace "HSLToRGB205" with the name of your function to test
  If RGBAsString(HSLToRGB205(0, 0, 0)) <> "0,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 0, 50)) <> "128,128,128" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 0, 100)) <> "255,255,255" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB205(0, 100, 1)) <> "5,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(120, 100, 1)) <> "0,5,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(240, 100, 1)) <> "0,0,5" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB205(0, 100, 50)) <> "255,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 100, 99)) <> "255,250,250" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 100, 100)) <> "255,255,255" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB205(180, 100, 100)) <> "255,255,255" Then Stop: fFailed = True
  
  ' color wheel:
  If RGBAsString(HSLToRGB205(0, 100, 50)) <> "255,0,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(60, 100, 50)) <> "255,255,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(120, 100, 50)) <> "0,255,0" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(180, 100, 50)) <> "0,255,255" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(240, 100, 50)) <> "0,0,255" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(300, 100, 50)) <> "255,0,255" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(360, 100, 50)) <> "255,0,0" Then Stop: fFailed = True
  
  If RGBAsString(HSLToRGB205(0, 25, 50)) <> "159,96,96" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 50, 50)) <> "191,64,64" Then Stop: fFailed = True
  If RGBAsString(HSLToRGB205(0, 100, 50)) <> "255,0,0" Then Stop: fFailed = True
  
  If fExact Then
    ' rounding errors might lead to one off
    If RGBAsString(HSLToRGB205(200, 13, 72)) <> "174,187,193" Then Stop: fFailed = True
    If RGBAsString(HSLToRGB205(201, 21, 63)) <> "141,167,180" Then Stop: fFailed = True
    If RGBAsString(HSLToRGB205(320, 88, 33)) <> "158,10,109" Then Stop: fFailed = True
    ' call 1,2,3,4
    If RGBAsString(HSLToRGB205(75, 50, 25)) <> "80,96,32" Then Stop: fFailed = True
    If RGBAsString(HSLToRGB205(0, 50, 25)) <> "96,32,32" Then Stop: fFailed = True
    If RGBAsString(HSLToRGB205(75, 0, 25)) <> "64,64,64" Then Stop: fFailed = True
    If RGBAsString(HSLToRGB205(320, 50, 0)) <> "0,0,0" Then Stop: fFailed = True
  End If
  
  ' validate check
  If RGBAsString(HSLToRGB205(480, 150, 150, True)) <> "255,255,255" Then Stop: fFailed = True
  
  ' well done
  IsGoodHSL2ToRGB = Not fFailed
  
End Function

Public Function RGBAsString(ByVal lRGB As Long) As String
  Dim R&, G&, B&
  R = lRGB And &HFF
  G = (lRGB And &HFF00&) \ &H100&
  B = (lRGB And &HFF0000) \ &H10000
  RGBAsString = R & "," & G & "," & B
End Function


Back to HSLToRGB