Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Sep 4, 2024
1 parent 742b0f2 commit 6bebe7e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

/**
* Tree converter built on a set of rules described in DSL.
*
* @since 1.0
*/
public class Adapter {
Expand Down Expand Up @@ -62,10 +61,10 @@ public Adapter(final List<Converter> converters, final Factory factory) {
* @return A converted tree or empty tree if the conversion is impossible
*/
public Node convert(final Node root) {
final MutableNode convertible = new MutableNode(root);
Node result = convertible;
final MutableNode mutable = new MutableNode(root);
Node result = mutable;
final List<MutableNode> nodes = new ArrayList<>(0);
NodeListBuilder.buildNodeList(convertible, nodes);
NodeListBuilder.buildNodeList(mutable, nodes);
for (final MutableNode original : nodes) {
boolean converted = false;
for (final Converter converter : this.converters) {
Expand All @@ -92,10 +91,10 @@ public Node convert(final Node root) {
*/
public Node partialConvert(final int variant, final Node root) {
int conversions = 0;
final MutableNode convertible = new MutableNode(root);
Node result = convertible;
final MutableNode mutable = new MutableNode(root);
Node result = mutable;

Check warning on line 95 in src/main/java/org/cqfn/astranaut/core/algorithms/conversion/Adapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/cqfn/astranaut/core/algorithms/conversion/Adapter.java#L94-L95

Added lines #L94 - L95 were not covered by tests
final List<MutableNode> nodes = new ArrayList<>(0);
NodeListBuilder.buildNodeList(convertible, nodes);
NodeListBuilder.buildNodeList(mutable, nodes);

Check warning on line 97 in src/main/java/org/cqfn/astranaut/core/algorithms/conversion/Adapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/cqfn/astranaut/core/algorithms/conversion/Adapter.java#L97

Added line #L97 was not covered by tests
for (final MutableNode original : nodes) {
final Converter converter = this.converters.get(0);
final Node transformed = converter.convert(original, this.factory);
Expand All @@ -118,9 +117,9 @@ public Node partialConvert(final int variant, final Node root) {
*/
public int calculateConversions(final Node root) {
int conversions = 0;
final MutableNode convertible = new MutableNode(root);
final MutableNode mutable = new MutableNode(root);
final List<MutableNode> nodes = new ArrayList<>(0);
NodeListBuilder.buildNodeList(convertible, nodes);
NodeListBuilder.buildNodeList(mutable, nodes);
for (final MutableNode original : nodes) {
final Converter converter = this.converters.get(0);
final Node transformed = converter.convert(original, this.factory);
Expand Down Expand Up @@ -154,7 +153,6 @@ private static Node replace(final MutableNode original,
* Creates a list from nodes.
* The list is sorted in descending order of nodes depth in the tree.
* Leaf nodes are at the beginning of the list, and the last element is the root.
*
* @since 0.2.2
*/
private static class NodeListBuilder {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/cqfn/astranaut/core/base/DraftNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -134,6 +135,22 @@ public static Node create(final String description, final Map<String, Set<Node>>
return DraftNode.create(iterator, nodes);
}

/**
* Creates a node from the type name, data, and existing child nodes..
* @param type The type name
* @param data The data (in a textual format)
* @param children The list of children
* @return A new node
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Node create(final String type, final String data, final Node... children) {
final DraftNode.Constructor ctor = new DraftNode.Constructor();
ctor.setName(type);
ctor.setData(data);
ctor.setChildrenList(Arrays.asList(children));
return ctor.createNode();
}

/**
* Creates a tree based on its description (recursive method).
* @param iterator Iterator by description characters
Expand Down
Loading

0 comments on commit 6bebe7e

Please sign in to comment.