Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/dart_test_analyze_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ jobs:
dart_test_analyze_format:
runs-on: ubuntu-latest
container:
image: google/dart
image: dart:stable
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# - run: (echo 'deb http://deb.debian.org/debian buster main contrib non-free') > /etc/apt/sources.list.d/buster.list
- run: dart pub get
- run: dart format --set-exit-if-changed .
- run: dart test --coverage .
- run: dart pub run coverage:format_coverage -i . -l > coverage.lcov
- run: dart run coverage:format_coverage -i . -l > coverage.lcov
- run: dart analyze
8 changes: 4 additions & 4 deletions array/car_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ bool carPooling(List<List<int>> trips, int capacity) {
void main() {
List<List<int>> trips = [
[2, 1, 5],
[3, 3, 7]
[3, 3, 7],
];

List<List<int>> trips1 = [
[2, 1, 5],
[3, 5, 7]
[3, 5, 7],
];

List<List<int>> trips2 = [
[2, 2, 6],
[2, 4, 7],
[8, 6, 7]
[8, 6, 7],
];

List<List<int>> trips3 = [
[7, 5, 6],
[6, 7, 8],
[10, 1, 6]
[10, 1, 6],
];

test('test case 1', () => expect(carPooling(trips, 4), false));
Expand Down
22 changes: 18 additions & 4 deletions array/sorted_squared_array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ void main() {
});

test('test case 2', () {
expect(sortedSquaredArray([-7, -6, -5, -4, -3, -2, -1]),
[1, 4, 9, 16, 25, 36, 49]);
expect(sortedSquaredArray([-7, -6, -5, -4, -3, -2, -1]), [
1,
4,
9,
16,
25,
36,
49,
]);
});

test('test case 4', () {
expect(
sortedSquaredArray([1, 2, 3, 4, 5, 6, 7]), [1, 4, 9, 16, 25, 36, 49]);
expect(sortedSquaredArray([1, 2, 3, 4, 5, 6, 7]), [
1,
4,
9,
16,
25,
36,
49,
]);
});
}
89 changes: 48 additions & 41 deletions backtracking/open_knight_tour.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,70 +94,77 @@ void printBoard(List<List<int>> board) {
void main() {
test(('getValidPos: testCase #1'), () {
expect(
getValidPos([1, 3], 4),
equals([
[2, 1],
[0, 1],
[3, 2]
]));
getValidPos([1, 3], 4),
equals([
[2, 1],
[0, 1],
[3, 2],
]),
);
});

test(('getValidPos: testCase #3'), () {
expect(
getValidPos([1, 2], 5),
equals([
[2, 4],
[0, 4],
[2, 0],
[0, 0],
[3, 3],
[3, 1]
]));
getValidPos([1, 2], 5),
equals([
[2, 4],
[0, 4],
[2, 0],
[0, 0],
[3, 3],
[3, 1],
]),
);
});

test(('isComplete: testCase #1'), () {
expect(
isComplete([
[1]
]),
equals(true));
isComplete([
[1],
]),
equals(true),
);
});

test(('isComplete: testCase #2'), () {
expect(
isComplete([
[1, 2],
[3, 0]
]),
equals(false));
isComplete([
[1, 2],
[3, 0],
]),
equals(false),
);
});

test(('openKnightTour: testCase #1'), () {
expect(
openKnightTour(1),
equals([
[1]
]));
openKnightTour(1),
equals([
[1],
]),
);
});

test(('openKnightTour: testCase #2'), () {
expect(
openKnightTour(2),
equals([
[0, 0],
[0, 0]
]));
openKnightTour(2),
equals([
[0, 0],
[0, 0],
]),
);
});

test(('openKnightTour: testCase #3'), () {
expect(
openKnightTour(5),
equals([
[1, 14, 19, 8, 25],
[6, 9, 2, 13, 18],
[15, 20, 7, 24, 3],
[10, 5, 22, 17, 12],
[21, 16, 11, 4, 23]
]));
openKnightTour(5),
equals([
[1, 14, 19, 8, 25],
[6, 9, 2, 13, 18],
[15, 20, 7, 24, 3],
[10, 5, 22, 17, 12],
[21, 16, 11, 4, 23],
]),
);
});
}
5 changes: 3 additions & 2 deletions conversions/Decimal_To_Any.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ String decimalToAny(int value, int base) {
32: 'W',
33: 'X',
34: 'Y',
35: 'Z'
35: 'Z',
};

if (value == 0) return "0";
Expand All @@ -48,7 +48,8 @@ String decimalToAny(int value, int base) {
while (value > 0) {
int remainder = value % base;
value = value ~/ base;
output = (remainder < 10
output =
(remainder < 10
? remainder.toString()
: ALPHABET_VALUES[remainder] ?? '0') +
output;
Expand Down
4 changes: 2 additions & 2 deletions conversions/Integer_To_Roman.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ List<int> ArabianRomanNumbers = [
9,
5,
4,
1
1,
];

List<String> RomanNumbers = [
Expand All @@ -36,7 +36,7 @@ List<String> RomanNumbers = [
"IX",
"V",
"IV",
"I"
"I",
];

List<String> integer_to_roman(int num) {
Expand Down
3 changes: 2 additions & 1 deletion conversions/binary_to_decimal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ int binaryToDecimal(String binaryString) {
if ("01".contains(binaryString[i]) == false) {
throw FormatException("Non-binary value was passed to the function");
} else {
decimalValue += (pow(2, binaryString.length - i - 1).toInt() *
decimalValue +=
(pow(2, binaryString.length - i - 1).toInt() *
(int.tryParse(binaryString[i]) ?? 0));
}
}
Expand Down
3 changes: 2 additions & 1 deletion conversions/hexadecimal_to_decimal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ int hexadecimal_to_decimal(String hex_string) {
hex_table.containsKey(hex_string[i]) == false) {
throw Exception("Non-hex value was passed to the function");
} else {
decimal_val += pow(16, hex_string.length - i - 1).toInt() *
decimal_val +=
pow(16, hex_string.length - i - 1).toInt() *
(int.tryParse(hex_string[i]) ?? hex_table[hex_string[i]] ?? 0);
}
}
Expand Down
3 changes: 2 additions & 1 deletion conversions/hexadecimal_to_octal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ String hexadecimal_to_octal(String hex_val) {
break;
default:
throw new FormatException(
"An invalid value was passed to the function");
"An invalid value was passed to the function",
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion conversions/roman_to_integer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ int value(var r) {
return 100;
else if (r == 'D')
return 500;
else if (r == 'M') return 1000;
else if (r == 'M')
return 1000;
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions data_structures/Heap/Binary_Heap/Max_heap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class MaxHeap {

void _siftUp(int currentIndex) {
int parentIndex = (currentIndex - 1) ~/ 2;
while (
parentIndex >= 0 && this.heap[parentIndex] < this.heap[currentIndex]) {
while (parentIndex >= 0 &&
this.heap[parentIndex] < this.heap[currentIndex]) {
_swap(parentIndex, currentIndex, this.heap);
currentIndex = parentIndex;
parentIndex = (currentIndex - 1) ~/ 2;
Expand All @@ -41,8 +41,9 @@ class MaxHeap {
int childTwoIndex;

while (childOneIndex <= endIndex) {
childTwoIndex =
2 * currentIndex + 2 <= endIndex ? 2 * currentIndex + 2 : -1;
childTwoIndex = 2 * currentIndex + 2 <= endIndex
? 2 * currentIndex + 2
: -1;
int indexToSwap;
if (childTwoIndex != -1 && heap[childTwoIndex] > heap[childOneIndex]) {
indexToSwap = childTwoIndex;
Expand Down
9 changes: 5 additions & 4 deletions data_structures/Heap/Binary_Heap/min_heap_two.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class MinHeap {

void _siftUp(int currentIndex) {
int parentIndex = (currentIndex - 1) ~/ 2;
while (
parentIndex >= 0 && this.heap[parentIndex] > this.heap[currentIndex]) {
while (parentIndex >= 0 &&
this.heap[parentIndex] > this.heap[currentIndex]) {
_swap(parentIndex, currentIndex, this.heap);
currentIndex = parentIndex;
parentIndex = (currentIndex - 1) ~/ 2;
Expand All @@ -41,8 +41,9 @@ class MinHeap {
int childTwoIndex;

while (childOneIndex <= endIndex) {
childTwoIndex =
2 * currentIndex + 2 <= endIndex ? 2 * currentIndex + 2 : -1;
childTwoIndex = 2 * currentIndex + 2 <= endIndex
? 2 * currentIndex + 2
: -1;
int indexToSwap;
if (childTwoIndex != -1 && heap[childTwoIndex] < heap[childOneIndex]) {
indexToSwap = childTwoIndex;
Expand Down
8 changes: 5 additions & 3 deletions data_structures/Stack/balanced_brackets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ void main() {

test(('Balanced Bracket'), () {
expect(
isBalancedBrackets(
'(((((([[[[[[{{{{{{{{{{{{()}}}}}}}}}}}}]]]]]]))))))((([])({})[])[])[]([]){}(())'),
isTrue);
isBalancedBrackets(
'(((((([[[[[[{{{{{{{{{{{{()}}}}}}}}}}}}]]]]]]))))))((([])({})[])[])[]([]){}(())',
),
isTrue,
);
});
}
2 changes: 1 addition & 1 deletion data_structures/linked_list/linked_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Node<T> {
Node.before(this.next, this.value);
}

class LinkedListIterator<T> extends Iterator<T?> {
class LinkedListIterator<T> implements Iterator<T?> {
Node<T?>? _current;

@override
Expand Down
24 changes: 16 additions & 8 deletions data_structures/linked_list/merge_sorted_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,26 @@ ListNode? mergeTwoLists(ListNode? list1, ListNode? list2) {

void main() {
test('test case 1', () {
ListNode head1 =
ListNode(val: 1, next: ListNode(val: 2, next: ListNode(val: 4)));
ListNode head2 =
ListNode(val: 1, next: ListNode(val: 3, next: ListNode(val: 4)));
ListNode head1 = ListNode(
val: 1,
next: ListNode(val: 2, next: ListNode(val: 4)),
);
ListNode head2 = ListNode(
val: 1,
next: ListNode(val: 3, next: ListNode(val: 4)),
);
expect(mergeTwoLists(head1, head2).listValues(), [1, 1, 2, 3, 4, 4]);
});

test('test case 2', () {
ListNode head1 =
ListNode(val: 1, next: ListNode(val: 2, next: ListNode(val: 3)));
ListNode head2 =
ListNode(val: 4, next: ListNode(val: 5, next: ListNode(val: 6)));
ListNode head1 = ListNode(
val: 1,
next: ListNode(val: 2, next: ListNode(val: 3)),
);
ListNode head2 = ListNode(
val: 4,
next: ListNode(val: 5, next: ListNode(val: 6)),
);
expect(mergeTwoLists(head1, head2).listValues(), [1, 2, 3, 4, 5, 6]);
});
}
Loading