Assignment 2 init - Find Max and Min

This commit is contained in:
Iurii Tatishchev 2024-08-26 19:05:44 -07:00
commit 94af7f5f2f
Signed by: CaZzzer
GPG Key ID: 28BE602058C08557
19 changed files with 394 additions and 0 deletions

184
labMaxMin/.gitignore vendored Normal file
View File

@ -0,0 +1,184 @@
### Intellij template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

8
labMaxMin/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

6
labMaxMin/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
labMaxMin/.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/labMaxMin.iml" filepath="$PROJECT_DIR$/labMaxMin.iml" />
</modules>
</component>
</project>

6
labMaxMin/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

37
labMaxMin/Assignment.java Normal file
View File

@ -0,0 +1,37 @@
package labMaxMin;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Assignment {
public static int[] getMaxAndMin(int[] sequence) {
// Fill in here
return new int[] { 0, 0 };
}
public static void run(String input_path) {
int[] sequence;
int arraySize = 1;
try (BufferedReader br = new BufferedReader(new FileReader(input_path))) {
// Get the size of the sequence
arraySize = Integer.parseInt(br.readLine());
sequence = new int[arraySize];
// Read the sequence
for (int i = 0; i < arraySize; i++) {
sequence[i] = Integer.parseInt(br.readLine());
}
// Get max and min values
int[] maxAndMin = getMaxAndMin(sequence);
// Output
System.out.println(maxAndMin[0] + ";" + maxAndMin[1]);
} catch (IOException e) {
e.printStackTrace();
}
}
}

103
labMaxMin/TestAll.java Normal file
View File

@ -0,0 +1,103 @@
package labMaxMin;
import java.io.File;
import java.net.URL;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
public class TestAll {
public static void main(String[] args) {
processInputFiles();
}
public static void processInputFiles() {
try {
// Get the inputs and outputs directories
URL input_url = TestAll.class.getResource("inputs");
URL output_url = TestAll.class.getResource("outputs");
if (input_url == null) {
System.out.println("Cannot find folder \"inputs\"");
return;
}
if (output_url == null) {
System.out.println("Cannot find folder \"outputs\"");
return;
}
// Get the names of all the files in either directory
File input_folder = new File(input_url.getPath());
File[] input_files = input_folder.listFiles();
File output_folder = new File(output_url.getPath());
if (input_files == null) {
System.out.printf("No files in folder: %s\n", input_folder.getPath());
return;
}
// No need to check if output files exist, can still run inputs
// Capture the print statements from the assignment into printstream
ByteArrayOutputStream captured_bytestream = new ByteArrayOutputStream();
PrintStream captured_printstream = new PrintStream(captured_bytestream);
// Replace System.out with a local variable to capture prints
PrintStream stdout = System.out;
System.setOut(captured_printstream);
Integer total_tests = 0, passed_tests = 0;
for (File input_file : input_files) {
if (!input_file.isFile()) {
continue;
}
// Print which test is currently being run
stdout.println("Processing file: " + input_file.getName());
// Run the assignment on this input file
Assignment.run(input_file.getAbsolutePath());
// Ensure all the output from assignment goes to local variable
System.out.flush();
// Get the output from assignment into a String
String assignment_output = captured_bytestream.toString();
captured_bytestream.reset();
// Get the file contents for comparison
File output_file = new File(output_folder, input_file.getName());
// Check if a corresponding output file exists
if (!output_file.exists()) {
// Print the output to the console without grading
stdout.println("No corresponding output, result shown:");
stdout.println(assignment_output);
continue;
}
// Read the contents of the corresponding output file
total_tests++;
BufferedReader buffered_reader = new BufferedReader(new FileReader(output_file.getAbsolutePath()));
StringBuilder string_builder = new StringBuilder();
String line;
while ((line = buffered_reader.readLine()) != null) {
string_builder.append(line).append(System.lineSeparator());
}
buffered_reader.close();
String correct_output = string_builder.toString();
if (assignment_output.equals(correct_output)) {
// This test passes
passed_tests++;
stdout.println("Test Pass");
} else {
// This test does not pass
stdout.println("Test Fail:");
stdout.println("Expected:");
stdout.println(correct_output);
stdout.println("Actual:");
stdout.println(assignment_output);
}
// Indicate this test is done
stdout.println("=====");
}
stdout.printf("Result: %d/%d Tests Passed\n", passed_tests, total_tests);
System.setOut(stdout);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,2 @@
1
1

View File

@ -0,0 +1,3 @@
2
1
2

View File

@ -0,0 +1,4 @@
3
1
2
3

View File

@ -0,0 +1,5 @@
4
1
2
3
4

View File

@ -0,0 +1,6 @@
5
1
2
3
4
5

11
labMaxMin/labMaxMin.iml Normal file
View File

@ -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$" isTestSource="false" packagePrefix="labMaxMin" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1 @@
1;1

View File

@ -0,0 +1 @@
2;1

View File

@ -0,0 +1 @@
3;1

View File

@ -0,0 +1 @@
4;1

View File

@ -0,0 +1 @@
5;1