-
Notifications
You must be signed in to change notification settings - Fork 4
/
if_.rs
94 lines (76 loc) · 1.8 KB
/
if_.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use super::common::*;
use typenum::consts::*;
typ! {
fn IfTest1<Cond>(Cond: _) {
if Cond {
1
}
}
fn IfTest2<Cond>(Cond: _) {
if Cond {
1
} else {
-1
}
}
fn IfTest3<Cond>(Cond: Bit) {
let mut value = 0;
if Cond {
value = 1;
}
value
}
fn IfTest4<Cond>(Cond: Bit) {
let mut value = 0;
if Cond {
value = 1;
} else {
value = -1;
}
value
}
fn IfTest5<Input>(Input: Integer) {
let mut value: Integer = 0;
if Input < 5 {
value = 1;
} else {
value = -1;
}
let output = if value >= 0 {
7
} else {
-7
};
output
}
fn IfTest6<L, R>(L: Integer, R: Integer) {
if L % 2 == 1 {
if R % 2 == 1 {
3
} else {
2
}
} else if R % 2 == 1 {
1
} else {
0
}
}
}
#[test]
fn test() {
let _: AssertSameOp<IfTest1Op<B0>, ()> = ();
let _: AssertSameOp<IfTest1Op<B1>, ()> = ();
let _: AssertSameOp<IfTest2Op<B0>, N1> = ();
let _: AssertSameOp<IfTest2Op<B1>, P1> = ();
let _: AssertSameOp<IfTest3Op<B0>, Z0> = ();
let _: AssertSameOp<IfTest3Op<B1>, P1> = ();
let _: AssertSameOp<IfTest4Op<B0>, N1> = ();
let _: AssertSameOp<IfTest4Op<B1>, P1> = ();
let _: AssertSameOp<IfTest5Op<P4>, P7> = ();
let _: AssertSameOp<IfTest5Op<P5>, N7> = ();
let _: AssertSameOp<IfTest6Op<P4, P2>, Z0> = ();
let _: AssertSameOp<IfTest6Op<P4, P3>, P1> = ();
let _: AssertSameOp<IfTest6Op<P5, P2>, P2> = ();
let _: AssertSameOp<IfTest6Op<P7, P9>, P3> = ();
}