blob: 277e08f03dee998750b38e5cb665b075a160df0f (
plain)
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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
using System;
using System.Runtime.CompilerServices;
class child
{
static int Main()
{
const int Pass = 100;
const int Fail = -1;
int testResult = 0;
int divResult = 0;
try
{
divResult = div2(0, -1); // Should not throw an exception
if (divResult != 0)
{
testResult += 0x1000; // Wrong result
}
divResult = div2(Int32.MinValue, -1); // Should throw ArithmeticException
Console.WriteLine(divResult);
testResult += 0x10;
}
catch (System.ArithmeticException)
{
testResult += 1;
}
catch (System.Exception)
{
Console.WriteLine("Caught other exception for MinInt/-1");
testResult += 0x100;
}
try
{
divResult = div2(80442, 654); // Should not throw an exception
if (divResult != 123)
{
testResult += 0x2000; // Wrong result
}
divResult = div2(1, 0); // Should throw DivideByZeroException
Console.WriteLine(divResult);
testResult += 0x20;
}
catch (System.DivideByZeroException)
{
testResult += 2;
}
catch (System.Exception)
{
Console.WriteLine("Caught other exception for x/0");
testResult += 0x200;
}
if ((testResult & 1) != 1)
{
Console.WriteLine("Did not see Arithmetic exception");
}
if ((testResult & 2) != 2)
{
Console.WriteLine("Did not see Divide-by-zero exception");
}
Console.Write("testResult is 0x");
Console.WriteLine(testResult.ToString("x"));
if (testResult == 3)
return Pass;
else
return Fail;
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static int div2(int a, int b)
{
return a / b;
}
}
|