Skip to content

Commit

Permalink
11b - unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Benov committed Feb 21, 2024
1 parent 48ee1de commit 93c8a4e
Show file tree
Hide file tree
Showing 43 changed files with 977 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
486840
6192
417711
752513
52188
213615
418759
303453
925423
490451
260528
219552
23805
761211
289456
657985
410085
70199
329645
444526
926798
612062
848442
194546
222419
288136
14891
747982
638130
857684
154761
347939
907444
909565
906307
34485
519166
351237
988660
949645
856264
944758
960141
487251
559148
517883
342850
731529
962402
640698
564935
41575
241498
165806
292533
384482
898113
542642
317876
450545
10935
761514
814698
836503
116300
559929
889368
411540
923995
819078
750632
374216
132176
522465
256377
580968
554690
914008
611472
661092
918637
778039
520728
578117
588666
803825
11968
379092
821084
918402
493908
302527
931779
468983
197620
800223
622806
104486
689730
545937
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
public static void main(String[] args) {
List<Integer> numbers = new LinkedList<>();
try {
numbers = Files.readAllLines(Path.of("numbers_100.txt"))
.stream()
.map(Integer::parseInt)
// .mapToInt(Integer::parseInt)
.toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
// try {
// BufferedReader fr = new BufferedReader(
// new FileReader("numbers_100.txt")
// );
// String line;
// while((line = fr.readLine()) != null) {
// numbers.add(Integer.getInteger(line));
// }
// fr.close();
// } catch (FileNotFoundException e) {
// throw new RuntimeException(e);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }


System.out.println("Max: " + numbers
.stream()
.max(Comparator.comparingInt(a -> a))
);
System.out.println("Max: " + numbers
.stream()
.sorted((a, b) -> b - a)
.findFirst()
);

System.out.println("5 largest: " + numbers
.stream()
.sorted((a, b) -> b - a)
.limit(5)
.sorted((a, b) -> a - b)
.toList()
);

System.out.println("5 largest: " + numbers
.stream()
.sorted(Comparator.comparingInt(a -> a))
.skip(numbers.size() - 5)
.toList()
);

System.out.println("sum of digits of min: " + numbers
.stream()
.sorted()
.limit(1)
// .peek(a -> System.out.println(a))
.map(a -> a.toString().split(""))
.flatMap(Arrays::stream)
.map(Integer::parseInt)
.reduce(0, Integer::sum)
// .flatMapToInt(a -> Arrays.stream(a).map(Integer::parseInt))
// .toList()
);

System.out.println(numbers
.stream()
.filter(a -> a % 5 == 0)
.mapToInt(a -> a)
.sum()
);

System.out.println(numbers
.stream()
.collect(Collectors.groupingBy(
a -> a % 2 == 0 ? "even" : "odd"
))
);
System.out.println(numbers
.stream()

// <U> U reduce(U identity,
// BiFunction<U, ? super T, U> accumulator,
// BinaryOperator<U> combiner);
.reduce(
new HashMap<String, List<Integer>>(),
(map, val) -> {
String key = val % 2 == 0 ? "even" : "odd";

if(map.)

return map;
},
(a, b) ->
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 93c8a4e

Please sign in to comment.