github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/exttinygo/require/impl.go (about)

     1  /*
     2  * Copyright (c) 2023-present unTill Pro, Ltd.
     3  *  @author Michael Saigachenko
     4   */
     5  
     6  package assert
     7  
     8  import (
     9  	"math"
    10  	"strconv"
    11  
    12  	ext "github.com/voedger/voedger/pkg/exttinygo"
    13  )
    14  
    15  func floarToStr(f float64) string {
    16  	return strconv.FormatFloat(f, 'E', -1, int32bitsLength)
    17  }
    18  
    19  func EqualInt32(expected, actual int32) {
    20  	if expected != actual {
    21  		panic("Int32 not equal. Expected: " + strconv.FormatInt(int64(expected), 10) + butGotPhrase + strconv.FormatInt(int64(actual), 10))
    22  	}
    23  }
    24  
    25  func EqualInt64(expected, actual int64) {
    26  	if expected != actual {
    27  		panic("Int64 not equal. Expected: " + strconv.FormatInt(expected, 10) + butGotPhrase + strconv.FormatInt(actual, 10))
    28  	}
    29  }
    30  
    31  func EqualString(expected, actual string) {
    32  	if expected != actual {
    33  		panic("Strings not equal. Expected: [" + expected + "] but got [" + actual + "]")
    34  	}
    35  }
    36  
    37  func EqualBytes(expected, actual []byte) {
    38  	if len(expected) != len(actual) {
    39  		panic("Byte array lengths not equal")
    40  	}
    41  	for i := 0; i < len(expected); i++ {
    42  		if expected[i] != actual[i] {
    43  			panic("Byte arrays not equal")
    44  		}
    45  	}
    46  }
    47  
    48  func EqualQName(expected, actual ext.QName) {
    49  	if len(expected.Entity) != len(actual.Entity) || len(expected.FullPkgName) != len(actual.FullPkgName) {
    50  		panic("QName not equal. Expected: " + expected.FullPkgName + "." + expected.Entity + butGotPhrase + actual.FullPkgName + "." + actual.Entity)
    51  	}
    52  }
    53  
    54  func boolToStr(b bool) string {
    55  	if b {
    56  		return "true"
    57  	}
    58  	return "false"
    59  }
    60  
    61  func EqualBool(expected, actual bool) {
    62  	if expected != actual {
    63  		panic("Bool not equal. Expected: " + boolToStr(expected) + butGotPhrase + boolToStr(actual))
    64  	}
    65  }
    66  
    67  func EqualFloat32(expected float32, actual float32) {
    68  	if math.Abs(float64(expected-actual)) > delta {
    69  		panic("Float32 not equal. Expected: " + floarToStr(float64(expected)) + butGotPhrase + floarToStr(float64(actual)))
    70  	}
    71  }
    72  
    73  func EqualFloat64(expected float64, actual float64) {
    74  	if math.Abs(expected-actual) > delta {
    75  		panic("Float64 not equal. Expected: " + floarToStr(expected) + butGotPhrase + floarToStr(actual))
    76  	}
    77  }