Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Sep 3, 2024
1 parent aee056b commit b0888d2
Showing 1 changed file with 11 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.cqfn.astranaut.core.base.ChildDescriptor;
import org.cqfn.astranaut.core.base.DraftNode;
Expand All @@ -37,7 +38,6 @@

/**
* Testing {@link NodeAllocator} class.
*
* @since 1.0
*/
@SuppressWarnings("PMD.TooManyMethods")
Expand All @@ -52,9 +52,6 @@ class NodeAllocatorTest {
*/
private static final String EXPRESSION = "Expression";

/**
* Testing mapping with all obligatory children.
*/
@Test
void testAllNonOptionalChildrenMapping() {
final boolean result = this.testMapping(
Expand All @@ -71,9 +68,6 @@ void testAllNonOptionalChildrenMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the mapper with a list of nodes in which the order is mixed up.
*/
@Test
void testIncorrectOrderChildren() {
final boolean result = this.testMapping(
Expand All @@ -93,9 +87,6 @@ void testIncorrectOrderChildren() {
Assertions.assertTrue(result);
}

/**
* Testing the mapper with one node that should be not mapped.
*/
@Test
void testOneNodeNotMapped() {
final boolean result = this.testMapping(
Expand All @@ -110,10 +101,6 @@ void testOneNodeNotMapped() {
Assertions.assertTrue(result);
}

/**
* Testing the mapper with complex variant of children,
* where some children are obligatory, some - not.
*/
@Test
void testAllVariousChildrenMapping() {
final boolean result = this.testMapping(
Expand All @@ -134,10 +121,6 @@ void testAllVariousChildrenMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the case when the descriptor contains two children of the same type, and one
* of them is optional, but the list of nodes contains only one child of this type.
*/
@Test
void testOnlyNonOptionalFromVariousChildrenMapping() {
final boolean result = this.testMapping(
Expand All @@ -158,9 +141,6 @@ void testOnlyNonOptionalFromVariousChildrenMapping() {
Assertions.assertTrue(result);
}

/**
* Another complex test case.
*/
@Test
void testNonOptionalAndOptionalFromVariousChildrenMapping() {
final boolean result = this.testMapping(
Expand All @@ -182,11 +162,6 @@ void testNonOptionalAndOptionalFromVariousChildrenMapping() {
Assertions.assertTrue(result);
}

/**
* Test the case where the descriptor contains two mandatory nodes of the same type
* and another optional node. However, the node list contains only two nodes of this type.
* Therefore, these nodes must be distributed to the correct cells.
*/
@Test
void testNonOptionalAndOptionalOfSameTypeMapping() {
final boolean result = this.testMapping(
Expand All @@ -206,10 +181,6 @@ void testNonOptionalAndOptionalOfSameTypeMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the case where a descriptor contains several pairs of nodes, one required
* and one optional node of each type.
*/
@Test
void testNonOptionalOfSameTypeAsOptionalMapping() {
final boolean result = this.testMapping(
Expand All @@ -230,9 +201,6 @@ void testNonOptionalOfSameTypeAsOptionalMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the case where missed a non-optional child.
*/
@Test
void testMissingNonOptionalChildMapping() {
final boolean result = this.testMapping(
Expand All @@ -251,9 +219,6 @@ void testMissingNonOptionalChildMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the case where the node list has one extra child.
*/
@Test
void testExtraChildMapping() {
final boolean result = this.testMapping(
Expand All @@ -272,10 +237,6 @@ void testExtraChildMapping() {
Assertions.assertTrue(result);
}

/**
* Testing the case where the node list has one node
* that does not match with descriptors list.
*/
@Test
void testOneNotMatchedNode() {
final boolean result = this.testMapping(
Expand All @@ -296,10 +257,6 @@ void testOneNotMatchedNode() {
Assertions.assertTrue(result);
}

/**
* Testing the case when there are two optional nodes of the same type,
* accordingly the mapper cannot make the right choice.
*/
@Test
void testSideBySideControversialOptionalNodes() {
final boolean result = this.testMapping(
Expand All @@ -319,10 +276,6 @@ void testSideBySideControversialOptionalNodes() {
Assertions.assertTrue(result);
}

/**
* Testing the case when there are three optional nodes of the same type,
* accordingly the mapper cannot make the right choice.
*/
@Test
void testThreeControversialOptionalNodes() {
final boolean result = this.testMapping(
Expand All @@ -344,10 +297,6 @@ void testThreeControversialOptionalNodes() {
Assertions.assertTrue(result);
}

/**
* Testing the case when there are several separated optional nodes of the same type,
* accordingly the mapper cannot make the right choice.
*/
@Test
void testSeparatedControversialOptionalNodes() {
final boolean result = this.testMapping(
Expand All @@ -370,9 +319,6 @@ void testSeparatedControversialOptionalNodes() {
Assertions.assertTrue(result);
}

/**
* Testing the case when the node list has more records than the descriptors list.
*/
@Test
void testIncorrectNumberOfChildren() {
final boolean result = this.testMapping(
Expand All @@ -390,10 +336,6 @@ void testIncorrectNumberOfChildren() {
Assertions.assertTrue(result);
}

/**
* Mapper testing when nodes in the list have a type that is inherited
* from the type specified in the descriptor.
*/
@Test
void testMappingWithInheritance() {
final List<ChildDescriptor> descriptors = Arrays.asList(
Expand All @@ -420,10 +362,6 @@ void testMappingWithInheritance() {
Assertions.assertEquals(third, mapping[1]);
}

/**
* Mapper testing when nodes in the list have a type that is inherited
* from the type that is inherited from another type specified in the descriptor.
*/
@Test
void testMappingWithTwoLevelInheritance() {
final List<ChildDescriptor> descriptors = Arrays.asList(
Expand All @@ -441,6 +379,16 @@ void testMappingWithTwoLevelInheritance() {
Assertions.assertTrue(result);
}

@Test
void testEmptyInput() {
final boolean result = this.testMapping(
Collections.emptyList(),
Collections.emptyList(),
true
);
Assertions.assertTrue(result);
}

/**
* Common test for the {@link NodeAllocator} class.
* @param types The list of types
Expand Down

0 comments on commit b0888d2

Please sign in to comment.