• No se han encontrado resultados

this.maximumEndpoint = maximumEndpoint

N/A
N/A
Protected

Academic year: 2022

Share "this.maximumEndpoint = maximumEndpoint"

Copied!
83
0
0

Texto completo

(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)

public abstract class Interval {

private static final String SEPARADOR = ", ";

protected Endpoint minimumEndpoint;

protected Endpoint maximumEndpoint;

protected Interval(Endpoint minimumEndpoint, Endpoint maximumEndpoint) {

this.minimumEndpoint = minimumEndpoint;

this.maximumEndpoint = maximumEndpoint;

}

public double midPoint() {

return minimumEndpoint.midPoint(maximumEndpoint);

} }

(13)

@Test

public void midPointTest() {

assertEquals(5, IntervalFactory.getInterval(0, 10, Opening.BOTH_OPENED).midPoint(), 0.0);

assertEquals(5, IntervalFactory.getInterval(0, 10, Opening.LEFT_OPENED).midPoint(), 0.0);

assertEquals(5, IntervalFactory.getInterval(0, 10, Opening.RIGHT_OPENED).midPoint(), 0.0);

assertEquals(5, IntervalFactory.getInterval(0, 10, Opening.UNOPENED).midPoint(), 0.0);

assertEquals(0, IntervalFactory.getInterval(-10, 10, Opening.BOTH_OPENED).midPoint(), 0.0);

assertEquals(0, IntervalFactory.getInterval(-10, 10, Opening.LEFT_OPENED).midPoint(), 0.0);

assertEquals(0, IntervalFactory.getInterval(-10, 10, Opening.RIGHT_OPENED).midPoint(), 0.0);

assertEquals(0, IntervalFactory.getInterval(-10, 10, Opening.UNOPENED).midPoint(), 0.0);

assertEquals(-10, IntervalFactory.getInterval(-15, -5, Opening.BOTH_OPENED).midPoint(), 0.0);

assertEquals(-10, IntervalFactory.getInterval(-15, -5, Opening.LEFT_OPENED).midPoint(), 0.0);

assertEquals(-10, IntervalFactory.getInterval(-15, -5, Opening.RIGHT_OPENED).midPoint(), 0.0);

assertEquals(-10, IntervalFactory.getInterval(-15, -5, Opening.UNOPENED).midPoint(), 0.0);

}

(14)

private static final int [] MINIMUN = {0, 0, 0, 0, -10, - 10, -10, -10, -15, -15, -15, -15};

private static final int [] MAXIMUN = {10, 10, 10, 10, 10, 10, 10, 10, -5, -5, -5, -5};

private static final Opening [] OPENING = {Opening.BOTH_OPENED, Opening.LEFT_OPENED, Opening.RIGHT_OPENED, Opening.UNOPENED, Opening.BOTH_OPENED, Opening.LEFT_OPENED, Opening.RIGHT_OPENED, Opening.UNOPENED, Opening.BOTH_OPENED, Opening.LEFT_OPENED, Opening.RIGHT_OPENED, Opening.UNOPENED};

private static final double [] RETURN_VALUE = {5, 5, 5, 5, 0, 0, 0, 0, -10, -10, -10, -10};

(15)
(16)
(17)
(18)

public int m1(boolean x) {

return value1 + value2 + (x ? 1 : 0);

}

@Test

public void testM1Boolean() { while (data.hasNext()) {

data.next();

assertEquals(data.getM1BooleanResult(),

data.getClass1().m1(data.getM1BooleanParameter 0()));

} }

(19)

(20)
(21)

(22)

(23)

o

(24)

o

o

o

o

o

o

(25)

 o

o

o

o

o

o

(26)

o

o

o

o

o

o

(27)

o

(28)
(29)
(30)
(31)
(32)
(33)
(34)
(35)

(36)

(37)
(38)
(39)
(40)
(41)

(42)

(43)
(44)

java.lang.reflect.

name = clazz.getSimpleName();

clazz Class<?>

clazz.getDeclaredConstructors();

clazz.getDeclaredMethods();

method.getName();

void

method.getReturnType().getSimpleName();

(45)

parameter0

parameter2

(46)

private void build() {

for (File file : this.file.listFiles()) { if (file.isDirectory()) {

Margin.instance().inc();

this.packages.add(new ProjectPackage(file, this));

Margin.instance().dec();

} else if (file.isFile() &&

file.getName().endsWith(".class")) {

String className = this.name + "." + file.getName().split("\\.")[0];

try {

Margin.instance().inc();

this.clazzes.add(new

ProjectClazz(TestFrameworkClassLoader.

getClassLoader().loadClass(className), this));

Margin.instance().dec();

(47)

} } }

this.components.addAll(this.packages);

this.components.addAll(this.clazzes);

}

ProjectPackage ProjectClazz

ProjectMethodMember ProjectConstructorMember

CodeProject

ProjectPackage ProjectPackage

ProjectClazz

(48)

ProjectCodeFile ProjectPackage ProjectClazz

ProjectClazz

ProjectMethodMember ProjectConstructorMember

ProjectClazz

ProjectMethodMember ProjectConstructorMember

ProjectMethodMember ProjectConstructorMember ProjectParameterMember

ProjectMethodMember returnType

public class TestFrameworkClassLoader extends URLClassLoader{

private static TestFrameworkClassLoader classLoader;

private TestFrameworkClassLoader(URL[] path) { super(path);

}

(49)

}

public static void setClassLoaderByPath(String paths[]) {

try {

URL[] urls = new URL[paths.length];

for (int i = 0; i < paths.length; i++) { urls[i] = new URL("file:///"+paths[i]);

}

classLoader = new TestFrameworkClassLoader(urls);

} catch (MalformedURLException e) { e.printStackTrace();

} }

public static void setClassLoaderByPath(String path) { String[] paths = {path};

setClassLoaderByPath(paths);

} }

(50)

TestWriter

visit(ProjectClazz)

package package1;

import static org.junit.Assert.*;

import org.junit.After;

import org.junit.BeforeClass;

import org.junit.Test;

import package1.Class1;

import package1._dataReaders.Class1TestDataReader;

public class Class1Test {

(51)

@BeforeClass

public static void init() {

data = new Class1TestDataReader();

}

@After

public void reset() { data.reset();

}

public int m1(int x) {

return value1 + value2 + x;

}

@Test

public void testM1Int() { while (data.hasNext()) { data.next();

assertEquals(data.getM1IntResult(),

data.getClass1().m1(data.getM1IntParameter0()));

} }

public Class1() { value1 = 0;

value2 = 0;

}

(52)

@Test

public void testClass1() {

while (data.hasNext("Class1")) { Class1 class1 = data.getClass1();

fail("Not yet implemented");

} }

fail Not yet implemented close

data, Class1TestDataReader

DataReaderWriter

Class1TestDataReader TestDataReader

TestDataReader

hasNext next

DataReaderWriter

ProjectVisitor TestWriter

(53)

Class1TestDataReader

(54)

HeaderDataWriter

ProjectCode

(55)

ConfigCode

toJson ConfigCode

(56)
(57)
(58)
(59)

(60)
(61)

public class Class1 { private int value1;

private int value2;

public Class1() { value1 = 0;

value2 = 0;

}

public Class1(int value1) { this.value1 = value1;

this.value2 = 0;

}

public Class1(int value1, int value2) { this.value1 = value1;

this.value2 = value2;

}

public int m1() { return value1;

}

public int m1(int x) {

return value1 + value2 + x;

}

public int m1(float x) {

return value1 + value2 + (int) x;

}

(62)

public int m1(double x) {

return value1 + value2 + (int) x;

}

public int m1(boolean x) {

return value1 + value2 + (x ? 1 : 0);

}

public int m1(String x) {

return value1 + value2 + Integer.parseInt(x);

}

public int m1(int x, int y) {

return value1 + value2 + x + y;

}

@Override

public String toString() {

return "[value1: " + value1 + ", value2: "+ value2 +"]";

} }

package package1;

import static org.junit.Assert.*;

import org.junit.After;

import org.junit.BeforeClass;

import org.junit.Test;

import package1.Class1;

import package1._dataReaders.Class1TestDataReader;

public class Class1Test {

private static Class1TestDataReader data;

(63)

public static void init() {

data = new Class1TestDataReader();

}

@After

public void reset() { data.reset();

} @Test

public void testClass1IntInt() {

while (data.hasNext("Class1IntInt")) { Class1 class1 = data.getClass1();

fail("Not yet implemented");

} } @Test

public void testClass1Int() {

while (data.hasNext("Class1Int")) { Class1 class1 = data.getClass1();

fail("Not yet implemented");

} } @Test

public void testClass1() {

while (data.hasNext("Class1")) { Class1 class1 = data.getClass1();

fail("Not yet implemented");

} } @Test

public void testToString() { while (data.hasNext()) { data.next();

assertEquals(data.getToStringResult(), data.getClass1().toString());

} }

(64)

@Test

public void testM1Boolean() { while (data.hasNext()) { data.next();

assertEquals(data.getM1BooleanResult(),

data.getClass1().m1(data.getM1BooleanParameter0() ));

} } @Test

public void testM1String() { while (data.hasNext()) { data.next();

assertEquals(data.getM1StringResult(),

data.getClass1().m1(data.getM1StringParameter0()) );

} } @Test

public void testM1IntInt() { while (data.hasNext()) { data.next();

assertEquals(data.getM1IntIntResult(),

data.getClass1().m1(data.getM1IntIntParameter0(), data.getM1IntIntParameter1()));

} } @Test

public void testM1Float() { while (data.hasNext()) { data.next();

assertEquals(data.getM1FloatResult(),

data.getClass1().m1(data.getM1FloatParameter0()))

; } }

(65)

while (data.hasNext()) { data.next();

assertEquals(data.getM1DoubleResult(),

data.getClass1().m1(data.getM1DoubleParameter0()) );

} } @Test

public void testM1() {

while (data.hasNext()) { data.next();

assertEquals(data.getM1Result(), data.getClass1().m1());

} } @Test

public void testM1Int() { while (data.hasNext()) { data.next();

assertEquals(data.getM1IntResult(),

data.getClass1().m1(data.getM1IntParameter0()));

} } }

package package1._dataReaders;

import readers.TestDataReader;

import readers.exceptions.EmptyDataReaderException;

import readers.exceptions.InvalidDataReaderException;

import package1.Class1;

public class Class1TestDataReader extends TestDataReader {

(66)

private Class1 class1;

private final static String[] CONSTRUCTOR_NAMES = {"Class1IntInt", "Class1Int", "Class1"};

public Class1TestDataReader() {

super("C:\\Users\\CarlosDavid\\git\\exampleProject\\src\\test

\\resources\\package1\\Class1TestData.xlsx");

}

public boolean hasNext(String constructorName) { while (this.hasNext()) {

this.getDataReader().next();

if (this.existsConstructor(constructorName)) { return true;

} }

return false;

}

public void next() {

this.getDataReader().next();

int i = 0;

this.class1= null;

while (i < CONSTRUCTOR_NAMES.length &&

!this.existsConstructor(CONSTRUCTOR_NAMES[i])) { i++;

}

this.construct(CONSTRUCTOR_NAMES[i]);

}

public void next(String constructorName) { this.class1= null;

this.construct(constructorName);

}

private boolean existsConstructor(String constructorName) {

switch (constructorName) { case "Class1IntInt":

return existsConstructorClass1IntInt();

(67)

case "Class1":

return existsConstructorClass1();

default:

return false;

} }

private void construct(String constructorName) { switch (constructorName) {

case "Class1IntInt":

constructClass1IntInt();

break;

case "Class1Int":

constructClass1Int();

break;

case "Class1":

constructClass1();

break;

} }

public Class1 getClass1() { return this.class1;

}

private boolean existsConstructorClass1IntInt() { try {

this.getInt("getClass1IntIntParameter0");

this.getInt("getClass1IntIntParameter1");

} catch (EmptyDataReaderException e) { return false;

}

return true;

}

private void constructClass1IntInt() {

(68)

try {

int Class1IntIntParameter0 =

this.getInt("getClass1IntIntParameter0");

int Class1IntIntParameter1 =

this.getInt("getClass1IntIntParameter1");

this.class1= new Class1(Class1IntIntParameter0, Class1IntIntParameter1);

} catch (EmptyDataReaderException e) {}

}

private boolean existsConstructorClass1Int() { try {

this.getInt("getClass1IntParameter0");

} catch (EmptyDataReaderException e) { return false;

}

return true;

}

private void constructClass1Int() { try {

int Class1IntParameter0 =

this.getInt("getClass1IntParameter0");

this.class1= new Class1(Class1IntParameter0);

} catch (EmptyDataReaderException e) {}

}

private boolean existsConstructorClass1() { try {

String x = this.getString("getClass1");

if (!x.equalsIgnoreCase("x")) {

throw new InvalidDataReaderException("Data under column \"getClass1\" at row: "+

this.getDataReader().getRow()+ " should be x or X");

}

} catch (InvalidDataReaderException e) { System.out.println(e.getMessage());

System.exit(0);

} catch (EmptyDataReaderException e) { return false;

}

return true;

}

(69)

}

public String getToStringResult() { this.setTestTarget("testToString");

this.getDataReader().next();

String result = null;

try {

result = this.getString("getToStringResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getToStringResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1BooleanResult() {

this.setTestTarget("testM1Boolean");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1BooleanResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1BooleanResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public boolean getM1BooleanParameter0() { this.setTestTarget("testM1Boolean");

boolean result = false;

try {

result = this.getBoolean("getM1BooleanParameter0");

} catch (EmptyDataReaderException e) { System.out.println("Error in

getM1BooleanParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

(70)

public int getM1StringResult() {

this.setTestTarget("testM1String");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1StringResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1StringResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public String getM1StringParameter0() { this.setTestTarget("testM1String");

String result = null;

try {

result = this.getString("getM1StringParameter0");

} catch (EmptyDataReaderException e) { System.out.println("Error in

getM1StringParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1IntIntResult() {

this.setTestTarget("testM1IntInt");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1IntIntResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1IntIntResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

(71)

int result = 0;

try {

result = this.getInt("getM1IntIntParameter0");

} catch (EmptyDataReaderException e) { System.out.println("Error in

getM1IntIntParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1IntIntParameter1() { this.setTestTarget("testM1IntInt");

int result = 0;

try {

result = this.getInt("getM1IntIntParameter1");

} catch (EmptyDataReaderException e) { System.out.println("Error in

getM1IntIntParameter1");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1FloatResult() {

this.setTestTarget("testM1Float");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1FloatResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1FloatResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

(72)

public float getM1FloatParameter0() { this.setTestTarget("testM1Float");

float result = 0;

try {

result = this.getFloat("getM1FloatParameter0");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1FloatParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1DoubleResult() {

this.setTestTarget("testM1Double");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1DoubleResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1DoubleResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public double getM1DoubleParameter0() { this.setTestTarget("testM1Double");

double result = 0;

try {

result = this.getDouble("getM1DoubleParameter0");

} catch (EmptyDataReaderException e) { System.out.println("Error in

getM1DoubleParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

(73)

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1Result");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1Result");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1IntResult() {

this.setTestTarget("testM1Int");

this.getDataReader().next();

int result = 0;

try {

result = this.getInt("getM1IntResult");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1IntResult");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

}

public int getM1IntParameter0() { this.setTestTarget("testM1Int");

int result = 0;

try {

result = this.getInt("getM1IntParameter0");

} catch (EmptyDataReaderException e) {

System.out.println("Error in getM1IntParameter0");

System.out.println(e.getMessage());

System.exit(0);

}

return result;

} }

(74)
(75)

"packages": [ {

"classes": [ {

"constructors": [ {

"test": "",

"name": "Class1IntInt", "status": "GENERATE"

}, {

"test": "",

"name": "Class1Int", "status": "GENERATE"

}, {

"test": "",

"name": "Class1", "status": "GENERATE"

} ],

"methods": [ {

"test": "",

"name": "toString", "status": "GENERATE"

}, {

"test": "",

"name": "m1Boolean", "status": "GENERATE"

}, {

"test": "",

(76)

"name": "m1String", "status": "GENERATE"

}, {

"test": "",

"name": "m1IntInt", "status": "GENERATE"

}, {

"test": "",

"name": "m1Float", "status": "GENERATE"

}, {

"test": "",

"name": "m1Double", "status": "GENERATE"

}, {

"test": "", "name": "m1",

"status": "GENERATE"

}, {

"test": "",

"name": "m1Int", "status": "GENERATE"

} ],

"name": "Class1", "status": "GENERATE"

}, {

"constructors": [ {

"test": "",

"name": "Class2", "status": "GENERATE"

}, {

"test": "",

"name": "Class2String",

"status": "GENERATE"

(77)

"methods": [ {

"test": "",

"name": "getString", "status": "GENERATE"

}, {

"test": "", "name": "m2",

"status": "GENERATE"

}, {

"test": "",

"name": "m1Int", "status": "GENERATE"

}, {

"test": "",

"name": "m1String", "status": "GENERATE"

} ],

"name": "Class2", "status": "GENERATE"

} ],

"name": "package1", "packages": []

}, {

"classes": [ {

"constructors": [ {

"test": "",

"name": "Class3", "status": "GENERATE"

}, {

"test": "",

"name": "Class3Boolean",

(78)

"status": "GENERATE"

} ],

"methods": [ {

"test": "",

"name": "m3Boolean", "status": "GENERATE"

}, {

"test": "",

"name": "isValue", "status": "GENERATE"

} ],

"name": "Class3", "status": "GENERATE"

} ],

"name": "package2", "packages": []

}, {

"classes": [], "name": "spike", "packages": []

} ] } }

{

"code": {

"packages": [ {

"classes": [ {

"constructors": [

{

(79)

"status": "EXISTENT"

}, {

"test": "testClass1Int", "name": "Class1Int", "status": "EXISTENT"

}, {

"test": "testClass1", "name": "Class1", "status": "EXISTENT"

} ],

"methods": [ {

"test": "testToString", "name": "toString", "status": "EXISTENT"

}, {

"test": "testM1Boolean", "name": "m1Boolean", "status": "EXISTENT"

}, {

"test": "testM1String", "name": "m1String", "status": "EXISTENT"

}, {

"test": "testM1IntInt", "name": "m1IntInt", "status": "EXISTENT"

}, {

"test": "testM1Float", "name": "m1Float", "status": "EXISTENT"

}, {

"test": "testM1Double",

(80)

"name": "m1Double", "status": "EXISTENT"

}, {

"test": "testM1", "name": "m1",

"status": "EXISTENT"

}, {

"test": "testM1Int", "name": "m1Int", "status": "EXISTENT"

} ],

"name": "Class1", "status": "EXISTENT"

}, {

"constructors": [ {

"test": "testClass2", "name": "Class2", "status": "EXISTENT"

}, {

"test": "testClass2String", "name": "Class2String", "status": "EXISTENT"

} ],

"methods": [ {

"test": "testGetString", "name": "getString", "status": "EXISTENT"

}, {

"test": "testM2", "name": "m2",

"status": "EXISTENT"

}, {

"test": "testM1Int",

(81)

}, {

"test": "testM1String", "name": "m1String", "status": "EXISTENT"

} ],

"name": "Class2", "status": "EXISTENT"

} ],

"name": "package1", "packages": []

}, {

"classes": [ {

"constructors": [ {

"test": "testClass3", "name": "Class3", "status": "EXISTENT"

}, {

"test": "testClass3Boolean", "name": "Class3Boolean", "status": "EXISTENT"

} ],

"methods": [ {

"test": "testIsValue", "name": "isValue", "status": "EXISTENT"

}, {

"test": "testM3Boolean", "name": "m3Boolean", "status": "EXISTENT"

}

],

(82)

"name": "Class3", "status": "EXISTENT"

} ],

"name": "package2", "packages": []

}, {

"classes": [], "name": "spike", "packages": []

}

]

}

}

(83)

Referencias

Documento similar

18 import model.People; import model.Person; public class HelloPeopleOO { private static void usage { System.out.println"Usage: application.HelloPeople "; System.exit1; }

import java.awt.*; public class MyFrame extends Frame { public MyFrame String str { super str; } public static void main String argv[] { MyFrame fr=new MyFrame “Hola

public class Thread implements Runnable public final static int Thread.MIN_PRIORITY; public final static int Thread.NORM_PRIORITY; public final static int Thread.MAX_PRIORITY;

– private static members accessed through methods • If no objects exist, classname and public static method.. 26.9 Static Class

class java.lang.Math 11 Method Summary public static doubleabsdouble a public static int roundfloat a public static doubleceildouble a public static doublecosdouble a public static

Aly 19 public class Circle extends Shape{ private double radius; public Circle double radius { this.radius=radius; } public double getRadius{return radius;} Public

Aly 23 public class Circle extends Shape{ private double radius; public Circle double radius { this.radius=radius; } public double getRadius{return radius;} Public double

public class CreditCard{ private double limit; private int number; private double balance; public static double fimal MAX_LIMIT=2000; public CreditCardint number{