mardi 11 juillet 2017

Testcases for a simple sorting algorithm

I have to understand simple testing. I'm going to write an exam and I have really no idea how to determine all Testcases.

For example, I have the following java-code given:

import java.util.Arrays;

public class Sortierung {

    public int[]sortiere(int[] zusortieren) {
        int laenge = zusortieren.length;
        int[] sortiert = new int[laenge];
        for(int i = 0; i < laenge; i++) {
            sortiert[i] = zusortieren[i];
            for(int j = i; j < laenge; j++) {
                if(sortiert[i] > zusortieren[j]) {
                    int tmp = sortiert[i];
                    sortiert[i] = zusortieren[j];
                    zusortieren[j] = tmp;
                }
            }
        }
        return sortiert;
    }
}

We have given one example of a Testcase and a fitting result.

Case: new int[] { 5,4,3} => new int[] {3,4,5}

I have determined following testcases:

Case #1: null => Exception

Case #2: new char[] => Compilation Error

I think I should get away from thinking, java is type safe, because you could possibly enter a String-Array using an GUI but I do not know what I could pass to this method.

Any help, e.g. reference for reading, is appreciated!

Aucun commentaire:

Enregistrer un commentaire