mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-13 10:42:54 +00:00
@@ -25,6 +25,7 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.db.dao.CharacterFriendDAO;
|
||||
import com.l2jserver.db.dao.MySQL5DAOModule;
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.id.provider.IDProviderModule;
|
||||
@@ -55,7 +56,7 @@ public class CharacterFriendListTest {
|
||||
.getInstance(CharacterFriendDAO.class);
|
||||
friendDao.load(character);
|
||||
|
||||
for (final L2Character friend : character.getFriendList()) {
|
||||
for (final CharacterFriend friend : character.getFriendList()) {
|
||||
Assert.assertNotNull(friend);
|
||||
Assert.assertNotSame(friend.getID(), character.getID());
|
||||
Assert.assertFalse(friend.getID().equals(character.getID()));
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ScriptingServiceImplTest {
|
||||
.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ScriptingService.class).to(PreCompiledScriptingService.class)
|
||||
bind(ScriptingService.class).to(ScriptingServiceImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* l2jserver is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.game.scripting.impl.compiled;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.l2jserver.service.game.scripting.CompilationResult;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class PrecompiledScriptCompilerTest {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link com.l2jserver.service.game.scripting.impl.compiled.PrecompiledScriptCompiler#compile(java.lang.Iterable)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testCompileIterableOfFile() {
|
||||
final PrecompiledScriptCompiler compiler = new PrecompiledScriptCompiler();
|
||||
final CompilationResult result = compiler.compile(FileUtils.listFiles(
|
||||
new File("target/scripts/script/template"), new String[] { "class" }, true));
|
||||
System.out.println(result.getCompiledClasses()[0]);
|
||||
}
|
||||
}
|
||||
@@ -69,9 +69,9 @@ public class WorldEventDispatcherImplTest {
|
||||
|
||||
@Test
|
||||
public void testListeners1() throws InterruptedException {
|
||||
final L2Character character1 = new L2Character(null, null);
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(cidFactory.createID());
|
||||
final L2Character character2 = new L2Character(null, null);
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(cidFactory.createID());
|
||||
final Item item1 = new Item(null);
|
||||
item1.setID(iidFactory.createID());
|
||||
@@ -110,9 +110,9 @@ public class WorldEventDispatcherImplTest {
|
||||
|
||||
@Test
|
||||
public void testListeners2() throws InterruptedException {
|
||||
final L2Character character1 = new L2Character(null, null);
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(cidFactory.createID());
|
||||
final L2Character character2 = new L2Character(null, null);
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(cidFactory.createID());
|
||||
final Item item1 = new Item(null);
|
||||
item1.setID(iidFactory.createID());
|
||||
|
||||
@@ -57,28 +57,28 @@ public class WorldServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
final L2Character character = new L2Character(null, null);
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
final L2Character character = new L2Character(null, null);
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
world.remove(character);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
final L2Character character = new L2Character(null, null);
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
Assert.assertTrue(world.contains(character));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
final L2Character character1 = new L2Character(null, null);
|
||||
final L2Character character2 = new L2Character(null, null);
|
||||
final L2Character character1 = new L2Character(null);
|
||||
final L2Character character2 = new L2Character(null);
|
||||
final Item item1 = new Item(null);
|
||||
world.add(character1);
|
||||
world.add(character2);
|
||||
|
||||
@@ -27,112 +27,137 @@ import org.junit.Test;
|
||||
public class CalculatorTest {
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final Calculator calc = new Calculator();
|
||||
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>();
|
||||
|
||||
calc.add(0, new SetFunction(10));
|
||||
calc.add(1, new MultiplicationFunction(2));
|
||||
calc.add(2, new SetFunction(30));
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new SetFunction(2, 30));
|
||||
|
||||
Assert.assertEquals(30.0, calc.calculate());
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
calc.calculate(ctx);
|
||||
Assert.assertEquals(30.0, ctx.result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPercent() {
|
||||
final Calculator calc = new Calculator();
|
||||
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>();
|
||||
|
||||
calc.add(0, new SetFunction(10));
|
||||
calc.add(1, new MultiplicationFunction(2));
|
||||
calc.add(2, new PercentFunction(75));
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new PercentFunction(2, 75));
|
||||
|
||||
Assert.assertEquals(15.0, calc.calculate());
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
calc.calculate(ctx);
|
||||
Assert.assertEquals(15.0, ctx.result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplex() {
|
||||
final Calculator calc = new Calculator();
|
||||
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>();
|
||||
|
||||
calc.add(0, new SetFunction(10));
|
||||
calc.add(1, new MultiplicationFunction(2));
|
||||
calc.add(2, new PercentFunction(75));
|
||||
calc.add(3, new SumFunction(3));
|
||||
calc.add(4, new SubtractFunction(8));
|
||||
calc.add(5, new DivisionFunction(2));
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new PercentFunction(2, 75));
|
||||
calc.add(new SumFunction(3, 3));
|
||||
calc.add(new SubtractFunction(4, 8));
|
||||
calc.add(new DivisionFunction(5, 2));
|
||||
|
||||
Assert.assertEquals(5.0, calc.calculate());
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
calc.calculate(ctx);
|
||||
Assert.assertEquals(5.0, ctx.result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNesting() {
|
||||
final Calculator calc1 = new Calculator();
|
||||
final Calculator<CalculatorContext> calc1 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx1 = new CalculatorContext();
|
||||
|
||||
calc1.add(0, new SetFunction(10));
|
||||
calc1.add(1, new MultiplicationFunction(2));
|
||||
calc1.add(2, new PercentFunction(75));
|
||||
calc1.add(3, new SumFunction(3));
|
||||
calc1.add(4, new SubtractFunction(8));
|
||||
calc1.add(5, new DivisionFunction(2));
|
||||
Assert.assertEquals(5.0, calc1.calculate());
|
||||
calc1.add(new SetFunction(0, 10));
|
||||
calc1.add(new MultiplicationFunction(1, 2));
|
||||
calc1.add(new PercentFunction(2, 75));
|
||||
calc1.add(new SumFunction(3, 3));
|
||||
calc1.add(new SubtractFunction(4, 8));
|
||||
calc1.add(new DivisionFunction(5, 2));
|
||||
|
||||
final Calculator calc2 = new Calculator();
|
||||
calc1.calculate(ctx1);
|
||||
Assert.assertEquals(5.0, ctx1.result);
|
||||
|
||||
calc2.add(0, new MultiplicationFunction(2));
|
||||
calc2.add(1, new PercentFunction(75));
|
||||
calc2.add(2, new SumFunction(3));
|
||||
calc2.add(3, new SubtractFunction(8));
|
||||
calc2.add(4, new DivisionFunction(2));
|
||||
Assert.assertEquals(-2.5, calc2.calculate());
|
||||
final Calculator<CalculatorContext> calc2 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx2 = new CalculatorContext();
|
||||
|
||||
final Calculator calc3 = new Calculator();
|
||||
calc3.add(0, calc1);
|
||||
calc3.add(1, calc2);
|
||||
calc2.add(new MultiplicationFunction(0, 2));
|
||||
calc2.add(new PercentFunction(1, 75));
|
||||
calc2.add(new SumFunction(2, 3));
|
||||
calc2.add(new SubtractFunction(3, 8));
|
||||
calc2.add(new DivisionFunction(4, 2));
|
||||
|
||||
calc2.calculate(ctx2);
|
||||
Assert.assertEquals(-2.5, ctx2.result);
|
||||
|
||||
final Calculator<CalculatorContext> calc3 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx3 = new CalculatorContext();
|
||||
calc3.add(calc1);
|
||||
calc3.add(calc2);
|
||||
|
||||
// this should be executed
|
||||
calc2.add(5, new SumFunction(1));
|
||||
|
||||
Assert.assertEquals(2.25, calc3.calculate());
|
||||
calc2.add(new SumFunction(10, 1));
|
||||
|
||||
calc3.calculate(ctx3);
|
||||
Assert.assertEquals(2.25, ctx3.result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImporting() {
|
||||
final Calculator calc1 = new Calculator();
|
||||
final Calculator<CalculatorContext> calc1 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx1 = new CalculatorContext();
|
||||
|
||||
calc1.add(0, new SetFunction(10));
|
||||
calc1.add(2, new MultiplicationFunction(2));
|
||||
calc1.add(4, new PercentFunction(75));
|
||||
calc1.add(6, new SumFunction(3));
|
||||
calc1.add(8, new SubtractFunction(8));
|
||||
calc1.add(10, new DivisionFunction(2));
|
||||
Assert.assertEquals(5.0, calc1.calculate());
|
||||
calc1.add(new SetFunction(0, 10));
|
||||
calc1.add(new MultiplicationFunction(2, 2));
|
||||
calc1.add(new PercentFunction(4, 75));
|
||||
calc1.add(new SumFunction(6, 3));
|
||||
calc1.add(new SubtractFunction(8, 8));
|
||||
calc1.add(new DivisionFunction(10, 2));
|
||||
|
||||
final Calculator calc2 = new Calculator();
|
||||
calc1.calculate(ctx1);
|
||||
Assert.assertEquals(5.0, ctx1.result);
|
||||
|
||||
calc2.add(1, new MultiplicationFunction(2));
|
||||
calc2.add(3, new PercentFunction(75));
|
||||
calc2.add(5, new SumFunction(3));
|
||||
calc2.add(7, new SubtractFunction(8));
|
||||
calc2.add(9, new DivisionFunction(2));
|
||||
Assert.assertEquals(-2.5, calc2.calculate());
|
||||
final Calculator<CalculatorContext> calc2 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx2 = new CalculatorContext();
|
||||
|
||||
final Calculator calc3 = new Calculator();
|
||||
calc2.add(new MultiplicationFunction(1, 2));
|
||||
calc2.add(new PercentFunction(3, 75));
|
||||
calc2.add(new SumFunction(5, 3));
|
||||
calc2.add(new SubtractFunction(7, 8));
|
||||
calc2.add(new DivisionFunction(9, 2));
|
||||
|
||||
calc2.calculate(ctx2);
|
||||
Assert.assertEquals(-2.5, ctx2.result);
|
||||
|
||||
final Calculator<CalculatorContext> calc3 = new Calculator<CalculatorContext>();
|
||||
final CalculatorContext ctx3 = new CalculatorContext();
|
||||
calc3.importFunctions(calc1);
|
||||
calc3.importFunctions(calc2);
|
||||
|
||||
// this should not be executed
|
||||
calc2.add(5, new SumFunction(50));
|
||||
calc2.add(new SumFunction(11, 50));
|
||||
|
||||
Assert.assertEquals(1.25, calc3.calculate());
|
||||
calc3.calculate(ctx3);
|
||||
Assert.assertEquals(1.25, ctx3.result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRounding() {
|
||||
final Calculator calc1 = new Calculator();
|
||||
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>();
|
||||
|
||||
calc1.add(0, new MultiplicationFunction(2));
|
||||
calc1.add(1, new PercentFunction(75));
|
||||
calc1.add(2, new SumFunction(3));
|
||||
calc1.add(3, new SubtractFunction(8.1));
|
||||
calc1.add(4, new DivisionFunction(2));
|
||||
calc1.add(5, new RoundFunction());
|
||||
Assert.assertEquals(-3.0, calc1.calculate());
|
||||
calc.add(new MultiplicationFunction(0, 2));
|
||||
calc.add(new PercentFunction(1, 75));
|
||||
calc.add(new SumFunction(2, 3));
|
||||
calc.add(new SubtractFunction(3, 8.1));
|
||||
calc.add(new DivisionFunction(4, 2));
|
||||
calc.add(new RoundFunction(5));
|
||||
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
calc.calculate(ctx);
|
||||
Assert.assertEquals(-3.0, ctx.result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user