blob: d52c65ef8c06eee2fff928cd4688d1eb7ae3ac81 [file] [log] [blame]
import 'dart:math' show pi;
abstract class Shape {}
class Circle implements Shape {
Circle(this.radius);
final double radius;
}
class Square implements Shape {
Square(this.length);
final double length;
}
double calculateArea(Shape shape) => switch (shape) {
Square(length: var l) when l >= 0 => l * l,
Circle(radius: var r) when r >= 0 => pi * r * r,
Square(length: var l) when l < 0 => -1,
Circle(radius: var r) when r < 0 => -1,
Shape() => 0,
};
testMain() {}