Skip to content
Snippets Groups Projects
Commit 00e6be49 authored by W. Spencer Smith's avatar W. Spencer Smith
Browse files

Removing unnecessary files from L25.

parent 84ecac01
No related branches found
No related tags found
No related merge requests found
/**
* Author: S. Smith
* Revised: March 4, 2017
*
* Description: Testing all the modules
*/
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestIntegerSet.class,
TestVectorTSet.class
})
public class AllTests
{
}
/**
* Author: S. Smith
* Revised: March 5, 2017
*
* Description: Full exception
*/
public class FullException extends RuntimeException
{
public FullException()
{
}
public FullException(String reason)
{
super(reason);
}
public FullException(int full)
{
super("The container has reached its full size of " + full);
}
}
/**
* Author: S. Smith
* Revised: Mar 5, 2017
*
* Description: A Set ADT with elements of type T
*/
import java.util.ArrayList;
public class GenericSet<T>
{
protected ArrayList<T> s;
public final static int MAX_SIZE = 100;
public GenericSet()
{
s = new ArrayList<T>();
}
public Boolean mem(T t)
{
return s.contains(t);
}
public void add(T t)
{
//check exception for MAX_SIZE
if (s.size() == MAX_SIZE)
{
throw new FullException("Cannot add to set. Set is full.");
}
if (s.contains(t))
{
throw new MemberException("Cannot add to set. Member already exists.");
}
s.add(t);
}
public void del(T t)
{
if (s.contains(t))
{
throw new NotMemberException("Cannot delete the element. Not in set.");
}
s.remove(t);
}
public int size()
{
return s.size();
}
}
\ No newline at end of file
/**
* Author: S. Smith
* Revised: March 4, 2017
*
* Description: Set of Integers
*/
public class IntegerSet extends GenericSet<Integer>
{
}
######################################
# Author: Joost Vandorp, S. Smith #
# Revised: Thursday, Feb 24, 2017 #
# Description: "MAKEFILE" #
######################################
# Assumes JUnit is installed
JFLAGS = -g
JCLASS = -cp $(CLASSPATH):.:/opt/local/share/java/junit.jar:/opt/local/share/java/hamcrest-core.jar
#JCLASS = -cp $(CLASSPATH):.:/usr/share/java/junit4.jar # on mills
JC = javac
JVM = java
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $(JCLASS) $*.java
CLASSES = \
GenericSet.java \
IntegerSet.java \
TestIntegerSet.java \
FullException.java \
MemberException.java \
NotMemberException.java \
VectorT.java \
VectorTSet.java \
TestVectorTSet.java \
AllTests.java \
MAIN = AllTests
default: classes
classes: $(CLASSES:.java=.class)
test: $(MAIN).class
$(JVM) $(JCLASS) org.junit.runner.JUnitCore $(MAIN)
clean:
$(RM) *.class
/**
* Author: S. Smith
* Revised: March 5, 2017
*
* Description: Member exception
*/
public class MemberException extends RuntimeException
{
public MemberException()
{
}
public MemberException(String reason)
{
super(reason);
}
}
/**
* Author: S. Smith
* Revised: March 5, 2017
*
* Description: Not member exception
*/
public class NotMemberException extends RuntimeException
{
public NotMemberException()
{
}
public NotMemberException(String reason)
{
super(reason);
}
}
/**
* Author: S. Smith
* Revised: March 4, 2017
*
* Description: Testing IntegerSet Class
*/
import org.junit.*;
import static org.junit.Assert.*;
public class TestIntegerSet
{
private IntegerSet i;
@Before
public void setUp()
{
i = new IntegerSet();
}
@After
public void tearDown()
{
i = null;
}
@Test
public void testAdd()
{
i.add(6);
assertEquals(1, i.size());
assertTrue(i.mem(6));
}
@Test
public void testMem()
{
i.add(6);
assertTrue(i.mem(6));
assertFalse(i.mem(5));
}
}
/**
* Author: S. Smith
* Revised: March 4, 2017
*
* Description: Testing VectorTSet Class
*/
import org.junit.*;
import static org.junit.Assert.*;
public class TestVectorTSet
{
private VectorTSet p;
@Before
public void setUp()
{
p = new VectorTSet();
}
@After
public void tearDown()
{
p = null;
}
@Test
public void testAdd()
{
p.add(new VectorT(4, 5));
assertEquals(1, p.size());
//assertTrue(p.mem(new VectorT(4, 5)));
}
}
/**
* Author: S. Smith
* Revised: March 5, 2017
*
* Description: Vector ADT class
*/
import static java.lang.Math.*;
public class VectorT
{
protected double xc;
protected double yc;
public VectorT(double x, double y)
{
xc = x;
yc = y;
}
public double xcrd()
{
return xc;
}
public double ycrd()
{
return yc;
}
public double mag()
{
return sqrt(pow(xc, 2.0) + pow(yc, 2.0));
}
}
/**
* Author: S. Smith
* Revised: March 5, 2017
*
* Description: Set of VectorT
*/
public class VectorTSet extends GenericSet<VectorT>
{
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment