2021-06-19 09:29:36 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
class Switches
|
|
|
|
{
|
2024-11-01 19:01:21 -04:00
|
|
|
enum Shape
|
|
|
|
{
|
|
|
|
case Rectangle(int x, int y, int width, int height);
|
|
|
|
case Circle(int x, int y, int radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Switch0(Result<int> res)
|
2021-06-19 09:29:36 -07:00
|
|
|
{
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case .Ok(let a):
|
|
|
|
return 0;
|
|
|
|
case .Err(let b):
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2024-11-01 19:01:21 -04:00
|
|
|
|
|
|
|
static int Switch1(Shape shape)
|
|
|
|
{
|
|
|
|
switch (shape)
|
|
|
|
{
|
2024-11-01 19:09:30 -04:00
|
|
|
case .Circle(let x, let y, let radius) when x == 10:
|
2024-11-01 19:01:21 -04:00
|
|
|
return 12;
|
|
|
|
default:
|
|
|
|
return 23;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public static void TestBasics()
|
|
|
|
{
|
|
|
|
Result<int> val0 = .Ok(1);
|
|
|
|
Test.Assert(Switch0(val0) == 0);
|
|
|
|
val0 = .Err;
|
|
|
|
Test.Assert(Switch0(val0) == 1);
|
|
|
|
|
|
|
|
Shape shape = .Circle(10, 20, 30);
|
|
|
|
Test.Assert(Switch1(shape) == 12);
|
|
|
|
}
|
2021-06-19 09:29:36 -07:00
|
|
|
}
|
|
|
|
}
|