⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objecttypetests.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 2 页
字号:
        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int16", ObjTypeC.ToString(), "BO: Short")        Assert.AreEqual(3, resObj, "BO: Short(3)")        obj1 = s1        obj2 = s2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: String")        Assert.AreEqual(123, resObj, "BO: String(123)")    End Sub    <Test()> _ Public Sub BitOrObj_2()        ' pass different types to BitOrObj()        Dim obj1 As Object        Dim obj2 As Object        Dim b1 As Byte = 5        Dim b2 As Byte = 3        Dim bool1 As Boolean = True        Dim bool2 As Boolean = True        Dim dbl1 As Double = 3D        Dim dbl2 As Double = 3D        Dim sn1 As Single = 1        Dim sn2 As Single = 5        Dim dec1 As Decimal = 3.4        Dim dec2 As Decimal = 4.4        Dim l1 As Long = 1234567        Dim l2 As Long = 1234568        Dim i1 As Integer = 7        Dim i2 As Integer = 3        Dim short1 As Short = 2        Dim short2 As Short = 1        Dim s1 As String = "112"        Dim s2 As String = "112"        Dim resObj As Object        Dim ObjTypeC As TypeCode        ' Byte - Single        obj1 = b1        obj2 = sn2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: Byte - Single")        Assert.AreEqual(5, resObj, "BO: Single(5)")        ' Single - Double        obj1 = sn1        obj2 = dbl2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: Single - Double")        Assert.AreEqual(3, resObj, "BO: Double(3)")        ' short - bool        obj1 = short1        obj2 = bool2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int16", ObjTypeC.ToString(), "BO: short - bool")        Assert.AreEqual(-1, resObj, "BO: Short(-1)")        ' short - string        obj1 = s1        obj2 = short2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: short - string")        Assert.AreEqual(113, resObj, "BO: Double(113)")        ' decimal - bool        obj1 = dec1        obj2 = bool2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: decimal - bool")        Assert.AreEqual(-1, resObj, "BO: decimal#1(-1)")        ' bool - decimal        obj1 = bool1        obj2 = dec1        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: bool - decimal")        Assert.AreEqual(-1, resObj, "BO: decimal#2(-1)")        ' Nothing - decimal        obj1 = Nothing        obj2 = dec2        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        '  Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: Nothing - decimal")        Assert.AreEqual(4, resObj, "BO: decimal(4)")        ' decimal - Nothing        obj1 = dec1        obj2 = Nothing        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        ' Assert.AreEqual("Int64", ObjTypeC.ToString(), "BO: decimal - Nothing")        Assert.AreEqual(3, resObj, "BO: decimal(3)")        ' short - Nothing        obj1 = short1        obj2 = Nothing        resObj = ObjectType.BitOrObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        ' Assert.AreEqual("Int16", ObjTypeC.ToString(), "BO: short - Nothing")        Assert.AreEqual(2, resObj, "BO: short(2)")    End Sub    <Test()> _    Public Sub BitXorObj_1()        ' pass same types to BitXorObj()        Dim obj1 As Object        Dim obj2 As Object        Dim b1 As Byte = 5        Dim b2 As Byte = 3        Dim bool1 As Boolean = True        Dim bool2 As Boolean = True        Dim dbl1 As Double = 3D        Dim dbl2 As Double = 3D        Dim sn1 As Single = 1        Dim sn2 As Single = 5        Dim dec1 As Decimal = 3.4        Dim dec2 As Decimal = 4.4        Dim l1 As Long = 1234567        Dim l2 As Long = 1234568        Dim i1 As Integer = 7        Dim i2 As Integer = 3        Dim short1 As Short = 2        Dim short2 As Short = 1        Dim s1 As String = "123"        Dim s2 As String = "123"        Dim resObj As Object        Dim ObjTypeC As TypeCode        obj1 = b1        obj2 = b2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Byte", ObjTypeC.ToString(), "BX: Byte ")        Assert.AreEqual(6, resObj, "BX: Byte(6)")        obj1 = bool1        obj2 = bool2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Boolean", ObjTypeC.ToString(), "BX: Boolean")        Assert.AreEqual(False, resObj, "BX: Boolean(False)")        obj1 = dbl1        obj2 = dbl2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Double")        Assert.AreEqual(0, resObj, "BX: Double(0)")        obj1 = sn1        obj2 = sn2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Single")        Assert.AreEqual(4, resObj, "BX: Single(4)")        obj1 = dec1        obj2 = dec2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Decimal")        Assert.AreEqual(7, resObj, "BX: Decimal(0)")        obj1 = l1        obj2 = l2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Long")        Assert.AreEqual(15, resObj, "BX: Long(15)")        obj1 = i1        obj2 = i2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int32", ObjTypeC.ToString(), "BX: Integer")        Assert.AreEqual(4, resObj, "BX: Integer(4)")        obj1 = short1        obj2 = short2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int16", ObjTypeC.ToString(), "BX: Short")        Assert.AreEqual(3, resObj, "BX: Short(3)")        obj1 = s1        obj2 = s2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: String")        Assert.AreEqual(0, resObj, "BX: String(0)")    End Sub    <Test()> _ Public Sub BitXorObj_2()        ' pass different types to BitXorObj()        Dim obj1 As Object        Dim obj2 As Object        Dim b1 As Byte = 5        Dim b2 As Byte = 3        Dim bool1 As Boolean = True        Dim bool2 As Boolean = True        Dim dbl1 As Double = 3D        Dim dbl2 As Double = 3D        Dim sn1 As Single = 1        Dim sn2 As Single = 5        Dim dec1 As Decimal = 3.4        Dim dec2 As Decimal = 4.4        Dim l1 As Long = 1234567        Dim l2 As Long = 1234568        Dim i1 As Integer = 7        Dim i2 As Integer = 3        Dim short1 As Short = 2        Dim short2 As Short = 1        Dim s1 As String = "112"        Dim s2 As String = "112"        Dim resObj As Object        Dim ObjTypeC As TypeCode        ' Byte - Single        obj1 = b1        obj2 = sn2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Byte - Single")        Assert.AreEqual(0, resObj, "BX: Single(0)")        ' Single - Double        obj1 = sn1        obj2 = dbl2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Single - Double")        Assert.AreEqual(2, resObj, "BX: Double(2)")        ' short - bool        obj1 = short1        obj2 = bool2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int16", ObjTypeC.ToString(), "BX: short - bool")        Assert.AreEqual(-3, resObj, "BX: Short(-3)")        ' short - string        obj1 = s1        obj2 = short2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: short - string")        Assert.AreEqual(113, resObj, "BX: Double(113)")        ' decimal - bool        obj1 = dec1        obj2 = bool2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: decimal - bool")        Assert.AreEqual(-4, resObj, "BX: decimal#1(-4)")        ' bool - decimal        obj1 = bool1        obj2 = dec1        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: bool - decimal")        Assert.AreEqual(-4, resObj, "BX: decimal#2(-4)")        ' Nothing - decimal        obj1 = Nothing        obj2 = dec2        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        '  Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: Nothing - decimal")        Assert.AreEqual(4, resObj, "BX: decimal(4)")        ' decimal - Nothing        obj1 = dec1        obj2 = Nothing        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        ' Assert.AreEqual("Int64", ObjTypeC.ToString(), "BX: decimal - Nothing")        Assert.AreEqual(3, resObj, "BX: decimal(3)")        ' short - Nothing        obj1 = short1        obj2 = Nothing        resObj = ObjectType.BitXorObj(obj1, obj2)        ObjTypeC = Type.GetTypeCode(resObj.GetType())        ' Assert.AreEqual("Int16", ObjTypeC.ToString(), "BX: short - Nothing")        Assert.AreEqual(2, resObj, "BX: short(2)")    End SubEnd Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -