Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 29th, 2020 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // +build !solution
  2.  
  3. package testequal
  4.  
  5. import (
  6.     "fmt"
  7. )
  8.  
  9. func AreEqual(expected, actual interface{}) bool {
  10.     switch expected.(type) {
  11.     case []int:
  12.         expectedSlice := expected.([]int)
  13.         actualSlice := actual.([]int)
  14.        
  15.         if _, ok := actual.([]int); !ok {
  16.             return false, expectedSlice, actualSlice
  17.         }
  18.         if expectedSlice != nil && actualSlice == nil {
  19.             return false
  20.         }
  21.         if expectedSlice == nil && actualSlice != nil {
  22.             return false
  23.         }
  24.  
  25.         if len(expectedSlice) != len(actualSlice) {
  26.             return false
  27.         }
  28.         for idx, elem := range expectedSlice {
  29.             if elem != actualSlice[idx] {
  30.                 return false
  31.             }
  32.         }
  33.         return true
  34.     case map[string]string:
  35.         if _, ok := actual.(map[string]string); !ok {
  36.             return false
  37.         }
  38.         expectedMap := expected.(map[string]string)
  39.         actualMap := actual.(map[string]string)
  40.         if expectedMap != nil && actualMap == nil {
  41.             return false
  42.         }
  43.         if expectedMap == nil && actualMap != nil {
  44.             return false
  45.         }
  46.  
  47.         if len(expectedMap) != len(actualMap) {
  48.             return false
  49.         }
  50.         for key, elem := range expectedMap {
  51.             if elem != actualMap[key] {
  52.                 return false
  53.             }
  54.         }
  55.         return true
  56.     case []byte:
  57.         if _, ok := actual.([]byte); !ok {
  58.             return false
  59.         }
  60.         expectedSlice := expected.([]byte)
  61.         actualSlice := actual.([]byte)
  62.         if expectedSlice != nil && actualSlice == nil {
  63.             return false
  64.         }
  65.         if expectedSlice == nil && actualSlice != nil {
  66.             return false
  67.         }
  68.  
  69.         if len(expectedSlice) != len(actualSlice) {
  70.             return false
  71.         }
  72.         for idx, elem := range expectedSlice {
  73.             if elem != actualSlice[idx] {
  74.                 return false
  75.             }
  76.         }
  77.         return true
  78.     case int:
  79.         return expected == actual
  80.     case int8:
  81.         return expected == actual
  82.     case int16:
  83.         return expected == actual
  84.     case int32:
  85.         return expected == actual
  86.     case int64:
  87.         return expected == actual
  88.     case uint8:
  89.         return expected == actual
  90.     case uint16:
  91.         return expected == actual
  92.     case uint32:
  93.         return expected == actual
  94.     case uint64:
  95.         return expected == actual
  96.     case string:
  97.         return expected == actual
  98.     default:
  99.         return false
  100.     }
  101. }
  102.  
  103. // AssertEqual checks that expected and actual are equal.
  104. //
  105. // Marks caller function as having failed but continues execution.
  106. //
  107. // Returns true if arguments are equal.
  108. func AssertEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool {
  109.     t.Helper()
  110.     if AreEqual(expected, actual) {
  111.         return true
  112.     }
  113.     msg := ""
  114.     if len(msgAndArgs) > 0 {
  115.         msg = msgAndArgs[0].(string)
  116.         t.Errorf(msg, expectedValue, actualValue)
  117.         // t.Errorf(msg)//, msgAndArgs[1:]...)
  118.     }
  119.     return false
  120. }
  121.  
  122. // AssertNotEqual checks that expected and actual are not equal.
  123. //
  124. // Marks caller function as having failed but continues execution.
  125. //
  126. // Returns true iff arguments are not equal.
  127. func AssertNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool {
  128.     t.Helper()
  129.     if AreEqual(expected, actual) {
  130.         fmt.Printf("\n\nlen %d\n[0] type %T\n[0] %v\n\n", len(msgAndArgs), msgAndArgs[0], msgAndArgs[0])
  131.  
  132.         msg := ""
  133.         if len(msgAndArgs) > 0 {
  134.             msg = msgAndArgs[0].(string)
  135.             t.Errorf(msg)//, msgAndArgs[1:]...)
  136.         }
  137.     return false
  138.     }
  139.     return true
  140. }
  141.  
  142. // RequireEqual does the same as AssertEqual but fails caller test immediately.
  143. func RequireEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) {
  144.     t.Helper()
  145.     if AssertEqual(t, expected, actual, msgAndArgs) {
  146.         return
  147.     }
  148.     t.FailNow()
  149. }
  150.  
  151. // RequireNotEqual does the same as AssertNotEqual but fails caller test immediately.
  152. func RequireNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) {
  153.     t.Helper()
  154.     if AssertNotEqual(t, expected, actual, msgAndArgs) {
  155.         return
  156.     }
  157.     t.FailNow()
  158. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top