Skip to content

Commit

Permalink
Add tests project for radial layout and add tests for center on root
Browse files Browse the repository at this point in the history
option

Signed-off-by: Max Kasperowski <[email protected]>
  • Loading branch information
Eddykasp committed Jul 4, 2023
1 parent 684b0f0 commit 96b490d
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
40 changes: 40 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.elk.alg.disco.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
formatter_profile=_Elk
formatter_settings_version=12
org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\n * Copyright (c) ${year} ${user} and others.\n * \n * This program and the accompanying materials are made available under the\n * terms of the Eclipse Public License 2.0 which is available at\n * http://www.eclipse.org/legal/epl-2.0.\n * \n * SPDX-License-Identifier: EPL-2.0 \n *******************************************************************************/</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Thu Sep 04 17:49:58 CEST 2008
eclipse.preferences.version=1
resolve.requirebundle=false
14 changes: 14 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ELK Layout DisCo Tests
Bundle-SymbolicName: org.eclipse.elk.alg.radial.test;singleton:=true
Bundle-Version: 0.9.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: com.google.guava;bundle-version="18.0.0",
org.eclipse.elk.core,
org.eclipse.elk.graph,
org.eclipse.elk.alg.common,
org.eclipse.elk.alg.radial,
org.eclipse.elk.alg.test,
org.junit;bundle-version="4.12.0"
Bundle-Vendor: Eclipse Modeling Project
36 changes: 36 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>

<p>November 30, 2017</p>
<h3>License</h3>

<p>
The Eclipse Foundation makes available all content in this plug-in
(&quot;Content&quot;). Unless otherwise indicated below, the Content
is provided to you under the terms and conditions of the Eclipse
Public License Version 2.0 (&quot;EPL&quot;). A copy of the EPL is
available at <a href="http://www.eclipse.org/legal/epl-2.0">http://www.eclipse.org/legal/epl-2.0</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.
</p>

<p>
If you did not receive this Content directly from the Eclipse
Foundation, the Content is being redistributed by another party
(&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the
Redistributor's license that was provided with the Content. If no such
license exists, contact the Redistributor. Unless otherwise indicated
below, the terms and conditions of the EPL still apply to any source
code in the Content and such source code may be obtained at <a
href="http://www.eclipse.org/">http://www.eclipse.org</a>.
</p>

</body>
</html>
13 changes: 13 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
###############################################################################
# Copyright (c) 2019 Kiel University and others.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
###############################################################################
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html
37 changes: 37 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017 Kiel University and others.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
SPDX-License-Identifier: EPL-2.0
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.elk</groupId>
<artifactId>parent</artifactId>
<version>0.9.0-SNAPSHOT</version>
<relativePath>../../build/pom.xml</relativePath>
</parent>

<groupId>org.eclipse.elk</groupId>
<artifactId>org.eclipse.elk.alg.radial.test</artifactId>
<version>0.9.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>

<build>
<plugins>
<!-- Don't publish this artifact to Maven repositories. -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2023 Kiel University and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.elk.alg.radial.test;

import static org.junit.Assert.assertEquals;

import org.eclipse.elk.alg.radial.RadialLayoutProvider;
import org.eclipse.elk.alg.radial.options.RadialOptions;
import org.eclipse.elk.alg.test.PlainJavaInitialization;
import org.eclipse.elk.core.math.ElkMargin;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.util.BasicProgressMonitor;
import org.eclipse.elk.graph.ElkEdge;
import org.eclipse.elk.graph.ElkNode;
import org.eclipse.elk.graph.util.ElkGraphUtil;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Test for the center on root option.
*
*/
public class CenterOnRootTest {

@BeforeClass
public static void init() {
PlainJavaInitialization.initializePlainJavaLayout();
}

/**
* Layout a tree of height 1 and center it. The center point of the root
* node should be placed in the middle of the graph as defined by its width
* and height.
*/
@Test
public void testSimpleCentering() {
ElkNode parent = ElkGraphUtil.createGraph();
ElkNode root = ElkGraphUtil.createNode(parent);
ElkNode n1 = ElkGraphUtil.createNode(parent);
ElkEdge e1 = ElkGraphUtil.createSimpleEdge(root, n1);
ElkNode n2 = ElkGraphUtil.createNode(parent);
ElkEdge e2 = ElkGraphUtil.createSimpleEdge(root, n2);
ElkNode n3 = ElkGraphUtil.createNode(parent);
ElkEdge e3 = ElkGraphUtil.createSimpleEdge(root, n3);

parent.setProperty(CoreOptions.ALGORITHM, RadialOptions.ALGORITHM_ID);
parent.setProperty(RadialOptions.CENTER_ON_ROOT, true);

RadialLayoutProvider layoutProvider = new RadialLayoutProvider();
layoutProvider.layout(parent, new BasicProgressMonitor());

ElkMargin margins = root.getProperty(CoreOptions.MARGINS);
assertEquals("Horizontal centering", parent.getWidth()/2, root.getX() + margins.left + root.getWidth()/2, 0.1);
assertEquals("Vertical centering", parent.getHeight()/2, root.getY() + margins.top + root.getHeight()/2, 0.1);
}

/**
* Layout of a tree with a height larger than 1.
*/
@Test
public void testLargerGraphCentering() {
ElkNode parent = ElkGraphUtil.createGraph();
ElkNode root = ElkGraphUtil.createNode(parent);

ElkNode n1 = ElkGraphUtil.createNode(parent);
ElkEdge e1 = ElkGraphUtil.createSimpleEdge(root, n1);
ElkNode n2 = ElkGraphUtil.createNode(parent);
ElkEdge e2 = ElkGraphUtil.createSimpleEdge(root, n2);
ElkNode n3 = ElkGraphUtil.createNode(parent);
ElkEdge e3 = ElkGraphUtil.createSimpleEdge(root, n3);

ElkNode n11 = ElkGraphUtil.createNode(parent);
ElkEdge e11 = ElkGraphUtil.createSimpleEdge(n1, n11);
ElkNode n12 = ElkGraphUtil.createNode(parent);
ElkEdge e12 = ElkGraphUtil.createSimpleEdge(n1, n12);
ElkNode n13 = ElkGraphUtil.createNode(parent);
ElkEdge e13 = ElkGraphUtil.createSimpleEdge(n1, n13);

parent.setProperty(CoreOptions.ALGORITHM, RadialOptions.ALGORITHM_ID);
parent.setProperty(RadialOptions.CENTER_ON_ROOT, true);

RadialLayoutProvider layoutProvider = new RadialLayoutProvider();
layoutProvider.layout(parent, new BasicProgressMonitor());

ElkMargin margins = root.getProperty(CoreOptions.MARGINS);
assertEquals("Horizontal centering", parent.getWidth()/2, root.getX() + margins.left + root.getWidth()/2, 0.1);
assertEquals("Vertical centering", parent.getHeight()/2, root.getY() + margins.top + root.getHeight()/2, 0.1);
}

}
1 change: 1 addition & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<module>org.eclipse.elk.alg.disco.test</module>
<module>org.eclipse.elk.alg.force.test</module>
<module>org.eclipse.elk.alg.layered.test</module>
<module>org.eclipse.elk.alg.radial.test</module>
<module>org.eclipse.elk.alg.rectpacking.test</module>
<module>org.eclipse.elk.alg.spore.test</module>
<module>org.eclipse.elk.alg.test</module>
Expand Down

0 comments on commit 96b490d

Please sign in to comment.