Mercurial > pub > bltoolkit
comparison UnitTests/CS/Common/OperatorTest.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 #if ORACLE | |
3 using Oracle.DataAccess.Types; | |
4 #endif | |
5 using NUnit.Framework; | |
6 | |
7 using BLToolkit.Common; | |
8 | |
9 namespace Common | |
10 { | |
11 [TestFixture] | |
12 public class OperatorTest | |
13 { | |
14 [Test] | |
15 public void StringTest() | |
16 { | |
17 Assert.AreEqual("123456", Operator<string>.Addition("123", "456")); | |
18 | |
19 Assert.IsTrue(Operator<string>.Equality("123", "123")); | |
20 } | |
21 | |
22 [Test] | |
23 public void IntTest() | |
24 { | |
25 Assert.AreEqual(579, Operator<int>.Addition (123, 456)); | |
26 Assert.AreEqual(-333, Operator<int>.Subtraction(123, 456)); | |
27 | |
28 Assert.AreEqual(56088, Operator<int>.Multiply(123, 456)); | |
29 Assert.AreEqual(0, Operator<int>.Division(123, 456)); | |
30 Assert.AreEqual(123, Operator<int>.Modulus (123, 456)); | |
31 | |
32 | |
33 Assert.AreEqual(72, Operator<int>.BitwiseAnd (123, 456)); | |
34 Assert.AreEqual(507, Operator<int>.BitwiseOr (123, 456)); | |
35 Assert.AreEqual(435, Operator<int>.ExclusiveOr(123, 456)); | |
36 | |
37 Assert.AreEqual(-123, Operator<int>.UnaryNegation (123)); | |
38 Assert.AreEqual(-124, Operator<int>.OnesComplement(123)); | |
39 | |
40 Assert.IsTrue(Operator<int>.Equality (123, 123)); | |
41 Assert.IsTrue(Operator<int>.Inequality (123, 456)); | |
42 Assert.IsTrue(Operator<int>.GreaterThan (123, -56)); | |
43 Assert.IsTrue(Operator<int>.GreaterThanOrEqual(123, 123)); | |
44 Assert.IsTrue(Operator<int>.LessThan (123, 456)); | |
45 Assert.IsTrue(Operator<int>.LessThanOrEqual (-23, 123)); | |
46 } | |
47 | |
48 #if ORACLE | |
49 private class OracleDecimalOp : IOperable<OracleDecimal> | |
50 { | |
51 public OracleDecimal Addition (OracleDecimal op1, OracleDecimal op2) { return (op1 + op2); } | |
52 public OracleDecimal Subtraction (OracleDecimal op1, OracleDecimal op2) { return (op1 - op2); } | |
53 public OracleDecimal Multiply (OracleDecimal op1, OracleDecimal op2) { return (op1 * op2); } | |
54 public OracleDecimal Division (OracleDecimal op1, OracleDecimal op2) { return (op1 / op2); } | |
55 public OracleDecimal Modulus (OracleDecimal op1, OracleDecimal op2) { return (op1 % op2); } | |
56 | |
57 public OracleDecimal BitwiseAnd (OracleDecimal op1, OracleDecimal op2) { throw new InvalidOperationException(); } | |
58 public OracleDecimal BitwiseOr (OracleDecimal op1, OracleDecimal op2) { throw new InvalidOperationException(); } | |
59 public OracleDecimal ExclusiveOr (OracleDecimal op1, OracleDecimal op2) { throw new InvalidOperationException(); } | |
60 | |
61 public OracleDecimal UnaryNegation (OracleDecimal op) { return (-op); } | |
62 public OracleDecimal OnesComplement (OracleDecimal op) { throw new InvalidOperationException(); } | |
63 | |
64 public bool Equality (OracleDecimal op1, OracleDecimal op2) { return op1 == op2; } | |
65 public bool Inequality (OracleDecimal op1, OracleDecimal op2) { return op1 != op2; } | |
66 public bool GreaterThan (OracleDecimal op1, OracleDecimal op2) { return op1 > op2; } | |
67 public bool GreaterThanOrEqual(OracleDecimal op1, OracleDecimal op2) { return op1 >= op2; } | |
68 public bool LessThan (OracleDecimal op1, OracleDecimal op2) { return op1 < op2; } | |
69 public bool LessThanOrEqual (OracleDecimal op1, OracleDecimal op2) { return op1 <= op2; } | |
70 } | |
71 | |
72 [Test] | |
73 public void ExtensionTest() | |
74 { | |
75 Operator<OracleDecimal>.Op = new OracleDecimalOp(); | |
76 | |
77 Assert.AreEqual((OracleDecimal)579, Operator<OracleDecimal>.Addition (123, 456)); | |
78 Assert.AreEqual((OracleDecimal)(-333),Operator<OracleDecimal>.Subtraction(123, 456)); | |
79 | |
80 Assert.AreEqual((OracleDecimal)56088, Operator<OracleDecimal>.Multiply(123, 456)); | |
81 Assert.AreEqual((OracleDecimal)41, Operator<OracleDecimal>.Division(123, 3)); | |
82 Assert.AreEqual((OracleDecimal)123, Operator<OracleDecimal>.Modulus (123, 456)); | |
83 | |
84 | |
85 Assert.AreEqual(-(OracleDecimal)123, Operator<OracleDecimal>.UnaryNegation (123)); | |
86 | |
87 Assert.IsTrue(Operator<OracleDecimal>.Equality (123, 123)); | |
88 Assert.IsTrue(Operator<OracleDecimal>.Inequality (123, 456)); | |
89 Assert.IsTrue(Operator<OracleDecimal>.GreaterThan (123, (-5))); | |
90 Assert.IsTrue(Operator<OracleDecimal>.GreaterThanOrEqual(123, 123)); | |
91 Assert.IsTrue(Operator<OracleDecimal>.LessThan (123, 456)); | |
92 Assert.IsTrue(Operator<OracleDecimal>.LessThanOrEqual (123, 123)); | |
93 } | |
94 #endif | |
95 } | |
96 } |