Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests. #19

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 134 additions & 15 deletions src/test/java/edu/ifrs/vvs/AppTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
/**
* @License
* Copyright 2020 Bubble Sort Application
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* @License Copyright 2020 Bubble Sort Application
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package edu.ifrs.vvs;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -28,8 +30,125 @@ class AppTest {
/**
* Rigorous Test.
*/
private static final Integer ZERO = 0;
private static final Integer MENOS_DOZE = -12;
private static final Integer MENOS_OITO = -8;
private static final Integer MENOS_SEIS = -6;
private static final Integer MENOS_UM = -1;
private static final Integer UM = 1;
private static final Integer DOIS = 2;
private static final Integer TRES = 3;
private static final Integer QUATRO = 4;
private static final Integer CINCO = 5;
private static final Integer SEIS = 6;
private static final Integer SETE = 7;
private static final Integer OITO = 8;
private static final Integer NOVE = 9;
private static final Integer DEZ = 10;

private final BubbleSort bubbleSort = new BubbleSort();
private final List<Integer> array = new ArrayList<>();

@BeforeEach
void init() {
array.add(DOIS);
array.add(OITO);
array.add(TRES);
array.add(QUATRO);
array.add(NOVE);
}

@AfterEach
public void restoreList() {
array.clear();
}

@Test
@DisplayName("Testing BubbleSort with positive numbers")
void testPositiveNumbers() {
int[] test = new int[array.size()];

for (int i = ZERO; i < array.size(); i++) {
test[i] = array.get(i);
}

bubbleSort.sort(test);

List<Integer> result = Arrays.stream(test)
.map(Integer::new)
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);

assertEquals(CINCO, result.size());

assertEquals(DOIS, result.get(ZERO));
assertEquals(TRES, result.get(UM));
assertEquals(QUATRO, result.get(DOIS));
assertEquals(OITO, result.get(TRES));
assertEquals(NOVE, result.get(QUATRO));
}

@Test
@DisplayName("Testing BubbleSort with positive and negative numbers")
void testPositiveAndNegativeNumbers() {
array.add(MENOS_UM);
array.add(MENOS_SEIS);
array.add(MENOS_OITO);
array.add(MENOS_DOZE);
array.add(ZERO);

int[] test = new int[array.size()];

for (int i = 0; i < array.size(); i++) {
test[i] = array.get(i);
}

bubbleSort.sort(test);

List<Integer> result = Arrays.stream(test)
.map(Integer::new)
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);

assertEquals(DEZ, result.size());

assertEquals(MENOS_DOZE, result.get(ZERO));
assertEquals(MENOS_OITO, result.get(UM));
assertEquals(MENOS_SEIS, result.get(DOIS));
assertEquals(MENOS_UM, result.get(TRES));
assertEquals(ZERO, result.get(QUATRO));

assertEquals(DOIS, result.get(CINCO));
assertEquals(TRES, result.get(SEIS));
assertEquals(QUATRO, result.get(SETE));
assertEquals(OITO, result.get(OITO));
assertEquals(NOVE, result.get(NOVE));
}

@Test
void testApp() {
assertEquals(1, 1);
@DisplayName("Testing BubbleSort with duplicate numbers")
void testDuplicateNumbers() {
array.add(NOVE);
array.add(NOVE);

int[] test = new int[array.size()];

for (int i = ZERO; i < array.size(); i++) {
test[i] = array.get(i);
}

bubbleSort.sort(test);

List<Integer> result = Arrays.stream(test)
.map(Integer::new)
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);

assertEquals(SETE, result.size());

assertEquals(DOIS, result.get(ZERO));
assertEquals(TRES, result.get(UM));
assertEquals(QUATRO, result.get(DOIS));
assertEquals(OITO, result.get(TRES));
assertEquals(NOVE, result.get(QUATRO));
assertEquals(NOVE, result.get(CINCO));
assertEquals(NOVE, result.get(SEIS));
}
}