Skip to content

Instantly share code, notes, and snippets.

@Bharathh-Raj
Bharathh-Raj / area_test.dart
Last active March 17, 2022 10:40
Flutter Unit Testing - setUp method
void main() {
late Area area;
setUp(() {
area = Area();
});
group("Area of the circle", () {
test("Area of the circle with radius 1 should be 3.141592", () {
// Arrange
@Bharathh-Raj
Bharathh-Raj / area_test.dart
Created March 16, 2022 17:40
Flutter Unit Testing - setUpAll method
void main() {
late Area area;
setUpAll(() {
area = Area();
});
group("Area of the circle", () {
test("Area of the circle with radius 1 should be 3.141592", () {
// Arrange
@Bharathh-Raj
Bharathh-Raj / area_test.dart
Created March 16, 2022 16:47
Flutter Unit Testing - Grouping
void main() {
group("Area of the circle",(){
test("Area of the circle with radius 1 should be 3.141592", () {
// Arrange
Area area = Area();
// Act
double result = area.circle(1);
// Assert
expect(result, 3.141592);
@Bharathh-Raj
Bharathh-Raj / area_test.dart
Created March 16, 2022 16:35
Flutter Unit Testing - Test Area of the Circle
void main() {
test("Area.pi should be 3.141592", () {
// Arrange
// Act
// Assert
expect(Area.pi, 3.141592);
});
}
@Bharathh-Raj
Bharathh-Raj / area_test.dart
Last active March 16, 2022 15:14
Flutter Unit Testing - Area of circle test
void main() {
test("Area of the circle with radius 1 should be 3.141592", () {
// Arrange
Area area = Area();
// Act
double result = area.circle(1);
// Assert
expect(result, 3.141592);
});
}
@Bharathh-Raj
Bharathh-Raj / area.dart
Last active March 16, 2022 15:04
Flutter Unit Testing - Area of the circle
class Area {
static double get pi => 3.141592;
double circle(double radius) {
return pi * radius.square;
}
}
extension NumSquare on num {
num get square => this * this;
@Bharathh-Raj
Bharathh-Raj / pubspec.yaml
Created March 16, 2022 13:25
Flutter Unit Testing Package Import
dev_dependencies:
flutter_test:
sdk: flutter
import 'package:flutter_test/flutter_test.dart';
void main() {
group("0 <= TestCases < 1K", () {
test("Passing 0", () {
expect(0.compactCount(), "0");
});
test("Passing 99", () {
expect(99.compactCount(), "99");
});
void main() {
int x = 5990000;
print(x.compactCount());
}
///If count is less than 1K, it returns the count as it is.
///This count never round to higher number eg. 9995690 -> 9.9M, It won't be 10M
extension CompactCount on int {
String compactCount() {
final Map<double, String> countMap = {
void _drawMinutesLine(Canvas canvas) {
for (int minute = 1; minute <= Constants.numberOfMinutes; minute++) {
final double _theta = Constants.angleBetweenEachMinuteLine * minute;
final double _radiusOfInnerPoint = _getInnerPointRadiusOfMinuteLine(minute);
final Offset _extremePoint =
GetOffset.getOffsetWithRadiusAndTheta(radius: _minuteLineExtremePointRadius, theta: _theta);
final Offset _innerPoint = GetOffset.getOffsetWithRadiusAndTheta(radius: _radiusOfInnerPoint, theta: _theta);
canvas.drawLine(_extremePoint, _innerPoint, _paint);