Commit fda0750a authored by michael lundquist's avatar michael lundquist
Browse files

Adding the code from class along with my standard CI test.

parent 7b078945
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
[*.yml]
indent_size = 2
[*.sh]
end_of_line = lf
# When shell scripts end in CRLF, bash gives a cryptic error message
*.sh text eol=lf
#
# Standard Maven .gitignore
#
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
#
# IntelliJ
#
*.iml
.idea/*
!.idea/runConfigurations/
#
# Visual Studio Code
#
.settings/
.classpath
.project
.vscode/
before_script:
- apt-get -qq update
- apt-get -qq upgrade
- export BUILD_DIR=$PWD
- apt-get -qq install default-jre
- apt-get -qq install default-jdk
- java -version
- update-alternatives --config java
- apt-get -qq install wget
- cd /opt
- wget ftp://mirror.reverse.net/pub/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
- tar xvf apache-maven-3.6.0-bin.tar.gz
- export M2_HOME=/opt/apache-maven-3.6.0
- export M2=$M2_HOME/bin
- export PATH=$M2:$PATH
- cd $BUILD_DIR/finalproject
- mvn -version
maven_build:
script: mvn verify
\ No newline at end of file
language: java
jdk: oraclejdk8
after_success:
- mvn coveralls:report
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ds.fourthassignment</groupId>
<artifactId>fourthassignment</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.10</version>
</dependency>
<dependency>
<groupId>com.github.ngeor</groupId>
<artifactId>checkstyle-rules</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<!--
You can run jacoco in the default profile with:
mvn jacoco:prepare-agent test jacoco:report
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
<profiles>
<!--
This profile enables jacoco when unit tests are run.
You can run it with mvn -P jacoco test.
It also activates itself on Travis.
-->
<profile>
<id>jacoco</id>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<phase>validate</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!--
For the Travis profile:
- we want to break the build on any checkstyle violation.
- we want to be able to publish coverage report to coveralls.
-->
<profile>
<id>travis</id>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
package com.ds.fourthassignment;
/**
* Hello world!
*/
public final class App {
private App() {
}
/**
* Says hello to the world.
* @param args The arguments of the program.
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
/**
*
* (50 points) Use the class TNode and TLinkedList discussed in the class and implement the following methods:a.(30 points) Search method to perform linear searchbased on the name field of a scientist object. If the query is found, remove and return the matched Scientist object. b.(20 points) Create an add method that keeps nodes sorted in descending order. 2-(30 points) Use the DoublyLinkedListand DoublyNodejava classesdiscussed in the class and change it to supportthedatatype Scientist provided in class. Implement the following method:a.Implement the method indexOfElement(Scientist s) to return the index of aninput element (based on the name of a scientist). Suppose the elements are unique. Add this method to class DoubleLinkedList.
*/
/**
* 3-(20 points) Use the CircularLinkedList java class to implement the following method and add it to the CircularLinkedListjava class(middle is neither at the beginning nor at the end):public void addToMiddle(LNode newNode) {//TODO }
*/
}
package com.ds.fourthassignment;
public class Scientist implements Comparable<Scientist>{
private String name;
public Scientist(){}
public Scientist(String name) {this.name = name; }
public String getName() {return name; }
public String toString() {return name; }
public int compareTo(Scientist o) {
if(this.name.compareToIgnoreCase(o.getName())<0) return -1;
else if (this.name.compareToIgnoreCase(o.getName())> 0) return 1;
else return 0;
}
}
\ No newline at end of file
package com.ds.fourthassignment;
public class TLinkedList {
private TNode head;
private int size;
public TLinkedList(){size = 0;}
/**
*
* @return True if the list is empty.
*/
public boolean isEmpty() {if (head==null) return true; else return false; }
/**
* Adds a node to the end of the linkedlist.
* @param node
*/
public void add(TNode node){
size++;
if(head==null) head = node; //if the linkedlist is empty
else{
TNode curr = head;
//if there is only one node in the linkedlist:
if(!curr.hasNext()) {
curr.setNext(node);
//curr= node;
}
//if there are multiple nodes inside the linkedlist
else{
//we need a loop
while(curr.hasNext()){
curr = curr.getNext();
}
curr.setNext(node);
}
}
}
/**
*This method adds nodes to the list and keeps the list sorted.
* @param node
*/
public void addSorted(TNode node){ //this method adds new nodes while keeping the list sorted.
if (isEmpty()) { //when the list is empty
add(node);
return;
}
TNode current = head;
TNode previous = current;
if(getSize()==1) { //when the list has only one node
if(node.getData().getName().compareTo(current.getData().getName()) <= 0 ){
node.setNext(current);
head = node;
size++;
}
else {
current.setNext(node);
size++;
}
return;
}
//when list has two or more nodes
previous = current;
current = current.getNext();
while(current!=null){
if(node.getData().getName().compareTo(current.getData().getName()) <= 0 ){
previous.setNext(node);
node.setNext(current);
size++;
return;
}
previous = current;
current = current.getNext();
}
previous.setNext(node);
size++;
}
/**
*
* @return and remove the last element in the linkedlist
*/
public Scientist remove(){
if(isEmpty()) return null;
TNode curr = head;
TNode previous = head;
//if there is only one element in the linkedlist:
if(!curr.hasNext()) {
Scientist data = curr.getData();
head= null;
return data;
}
else{ //multiple elemets inside the linkedlist
while(curr.hasNext()){
previous = curr;
curr = curr.getNext();
}
Scientist data = curr.getData();
previous.setNext(null);
curr = null;
return data;
}
}
/**
*
* @return the number of elements in the linkedlist.
*/
public int getSize(){ return size; }
}
\ No newline at end of file
package com.ds.fourthassignment;
public class TNode {
private Scientist data;
private TNode next; //link
public TNode(Scientist data, TNode next){
this.data = data;
this.next = next;
}
public void setData(Scientist data) { this.data = data; }
public void setNext(TNode next){ this.next = next; }
public Scientist getData(){return data; }
public TNode getNext() { return next; }
public boolean hasNext() {
if (next!=null) return true;
else return false;
}
}
\ No newline at end of file
package com.ds.fourthassignment;
//import java.util.LinkedList;
public class TestTLinkedList {
/**
* @param args
*/
public static void main(String[] args) {
TNode n1 = new TNode(new Scientist("C"), null);
TNode n2 = new TNode(new Scientist("A"), null);
TNode n3 = new TNode(new Scientist("B"), null);
TNode n4 = new TNode(new Scientist("J"), null);
TLinkedList list = new TLinkedList();
list.addSorted(n1);
list.addSorted(n2);
list.addSorted(n3);
list.addSorted(n4);
while(!list.isEmpty()){
System.out.println(list.remove());
}
}
}
\ No newline at end of file
package com.ds.fourthassignment;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Unit test for simple App.
*/
public class AppTest {
/**
* Rigorous Test.
*/
@Test
public void testApp() {
assertTrue(true);
}
}
package com.ds.fourthassignment;
import static org.junit.Assert.*;
import org.junit.Test;
//import Lecture_4.LinkedList.Scientist;
public class JUnit_Test_TLinkedList {
@Test
public void test() {
TNode n1 = new TNode(new Scientist("C"), null);
TNode n2 = new TNode(new Scientist("A"), null);
TNode n3 = new TNode(new Scientist("B"), null);
TNode n4 = new TNode(new Scientist("J"), null);
TLinkedList list = new TLinkedList();
list.addSorted(n1);
list.addSorted(n2);
list.addSorted(n3);
list.addSorted(n4);
String out="";
while(!list.isEmpty()){
out+=list.remove()+",";
}
assertEquals("J,C,B,A,", out);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment