Search in sources :

Example 1 with ChangeBlock

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock in project ArTEMiS by ls1intum.

the class CombineChangeBlocksTest method testCombineManyIntoOne2.

@Test
public void testCombineManyIntoOne2() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(1, 2, 3)), new ChangeBlock(List.of(3, 4, 5)), new ChangeBlock(List.of(4, 5, 6)), new ChangeBlock(List.of(7, 8, 9)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Example 2 with ChangeBlock

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock in project Artemis by ls1intum.

the class CombineChangeBlocksTest method testCombineManyIntoOne1.

@Test
public void testCombineManyIntoOne1() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(2)), new ChangeBlock(List.of(3)), new ChangeBlock(List.of(4)), new ChangeBlock(List.of(5)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(2, 3, 4, 5)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Example 3 with ChangeBlock

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock in project Artemis by ls1intum.

the class CombineChangeBlocksTest method testOneCombination2.

@Test
public void testOneCombination2() throws BehavioralSolutionEntryGenerationException {
    var changeBlocks = new ChangeBlock[] { new ChangeBlock(List.of(1, 2, 3, 4)), new ChangeBlock(List.of(3, 4, 5, 6, 7, 8)) };
    groupedFile.setCommonChanges(List.of(changeBlocks));
    assertThat(combineChangeBlocks.executeCondition()).isTrue();
    assertThat(combineChangeBlocks.executeAction()).isTrue();
    assertThat(groupedFile.getCommonChanges()).containsExactly(new ChangeBlock(List.of(1, 2, 3, 4, 5, 6, 7, 8)));
}
Also used : ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock) Test(org.junit.jupiter.api.Test)

Example 4 with ChangeBlock

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock in project Artemis by ls1intum.

the class AddUncoveredLinesAsPotentialCodeBlocks method executeAction.

@Override
public boolean executeAction() {
    boolean didChanges = false;
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        var newChangeBlocks = new TreeSet<ChangeBlock>();
        for (ChangeBlock commonChange : groupedFile.getCommonChanges()) {
            var firstLine = commonChange.getLines().first();
            var potentialPrefix = getPotentialPrefix(firstLine, groupedFile.getFileContent());
            if (potentialPrefix != null) {
                newChangeBlocks.add(potentialPrefix);
            }
            var lastLine = commonChange.getLines().last();
            var potentialPostfix = getPotentialPostfix(lastLine, groupedFile.getFileContent());
            if (potentialPostfix != null) {
                newChangeBlocks.add(potentialPostfix);
            }
        }
        if (!newChangeBlocks.isEmpty()) {
            groupedFile.getCommonChanges().addAll(newChangeBlocks);
            didChanges = true;
        }
    }
    return didChanges;
}
Also used : TreeSet(java.util.TreeSet) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock)

Example 5 with ChangeBlock

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock in project Artemis by ls1intum.

the class CreateSolutionEntries method executeAction.

@Override
public boolean executeAction() {
    var solutionEntries = new ArrayList<ProgrammingExerciseSolutionEntry>();
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        for (GroupedFile.ChangeBlock changeBlock : groupedFile.getCommonChanges()) {
            if (!changeBlock.isPotential()) {
                solutionEntries.add(createSolutionEntry(groupedFile, changeBlock));
            }
        }
    }
    if (solutionEntries.equals(blackboard.getSolutionEntries())) {
        return false;
    }
    blackboard.setSolutionEntries(solutionEntries);
    return !blackboard.getSolutionEntries().isEmpty();
}
Also used : GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList)

Aggregations

ChangeBlock (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock)10 Test (org.junit.jupiter.api.Test)8 GroupedFile (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile)4 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2