preload

1-1 Comparison: isValueLess

Posted by Albert Gareev on Jul 14, 2010 | Categories: Source codeVerification

Reference Page: Comparison Rules

Automatic Comparison Rules

Relationship: One-to-One / Rule: Is Value Less

Definitions

Supported data types: String, Number, Date

Comparison of values of different data types always returns False.
Comparison of values of unsupported data types always returns False.

Data type: String

Strings are compared based on total length and encoding of each character.

A string of shorter length is always considered lesser. (Updated 2010/07/20, see comments section)

Comparison of two strings is performed character by character up to the first character that differs. The string with the lesser character in that position is considered lesser.

Data type: Number

A lesser value is considered lesser than a bigger one. All negative numbers are less than zero and all positive numbers. Thus, -1 is less than 100; -100 is less than -1.

The floating-point value NaN (not a number) is greater than any other numeric value and is equal to itself.

Data type: Date

Date/time values are compared per component values: Year, Month, Day, Hour, Second.
A later date is considered greater than an earlier one. A date with a greater month but lesser year is considered less, and so forth.

Implementation

Public Function isValueLess(ByVal sActualValue, ByVal sExpectedValue, ByVal sFormat)

  If Not isSameFormat(sActualValue, sExpectedValue, sFormat) Then
    isValueLess = False
    Exit Function
  End If
 
  Select Case UCase(sFormat)
    Case "NUMBER"
     If CDbl(sActualValue) < CDbl(sExpectedValue) Then
       isValueLess = True
    Else
       isValueLess = False
     End If
    Case "DATE"  
      If DateDiff("s", CDate(sActualValue), CDate(sExpectedValue)) > 0 Then
      isValueLess = True
     Else
      isValueLess = False
     End If
   Case "STRING"
        If StrComp(sActualValue, sExpectedValue, vbBinaryCompare) = -1 Then
        isValueLess = True
        Else
        isValueLess = False
        End If
    Case Else 
      isValueLess = False
  End Select
End Function

Test Code

  Log.Message("1-1 Comparison: isValueLess")
 
  boolRC = isValueLess("aaaazzzz", "zzzzaaaa", "String")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If
  boolRC = isValueLess("ab", "abc", "String")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If
  boolRC = isValueLess("ab ", "abc", "String")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If

  boolRC = isValueLess(0, 1, "Number")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If
  boolRC = isValueLess(0, dblNearlyZero, "Number")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If
  boolRC = isValueLess(-1, 0, "Number")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If
  boolRC = isValueLess(-10, -1, "Number")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If

  sValue1 = CDate("01/01/01")
  sValue2 = CDate("1/1/2002")
  boolRC = isValueLess(sValue1, sValue2, "DATE")
  If Not boolRC Then
    Log.Error("isValueLess failed")
  End If

  sValue1 = CDate("31/12/2050")
  sValue2 = CDate("1/1/2050")
  boolRC = isValueLess(sValue1, sValue2, "DATE")
  If boolRC Then
    Log.Error("isValueLess failed")
  End If


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.