vendredi 26 février 2021

Multiple conditions inside IF statement refactoring

I need to provide validation for some things and this validation contains tons of conditions inside single If statement.

I'm looking for a possible way to refactor If statement below to make it more compact or just look nicer.

            if ((GetAverage(params1) / GetAverage(params2) >= 1.3
                && GetAverage(params3) / GetAverage(params4) >= 1.3
                && GetAverage(params5) / GetAverage(params6) >= 1.3
                && GetAverage(params7) / GetAverage(params8) >= 1.3
                && GetAverage(params9) / GetAverage(params10) >= 1.5
                && GetAverage(params11) / GetAverage(params12) >= 1.5
                && GetAverage(params13) / GetAverage(params14) >= 0.5
                && GetAverage(params15) / GetAverage(params16) >= 0.5
                && GetAverage(params17) / GetAverage(params18) >= 0.5
                && GetAverage(params19) / GetAverage(params20) >= 0.5)
                || 
                (val1 > val && GetAverage(params1) / GetAverage(params2) >= 1.5
                && GetAverage(params3) / GetAverage(params4) >= 1.25
                && GetAverage(params5) / GetAverage(params6) >= 0.75
                && GetAverage(params7) / GetAverage(params8) >= 0.75)
                ||
                (val2 > val1 && GetAverage(params1) / GetAverage(params2) >= 1.75
                && GetAverage(params3) / GetAverage(params4) >= 1.75
                && GetAverage(params5) / GetAverage(params6) >= 0.75
                && GetAverage(params7) / GetAverage(params8) >= 0.75
                && GetAverage(params9) / GetAverage(params10) >= 0.20)
                ||
                (val1 > val2 && GetAverage(params1) / GetAverage(params2) >= 0.75
                && GetAverage(params3) / GetAverage(params4) >= 0.80
                && GetAverage(params5) / GetAverage(params6) >= 0.20)
                ||
                (val2 > val1 && GetAverage(params1) / GetAverage(params2) >= 0.75
                && GetAverage(params3) / GetAverage(params4) >= 0.80
                && GetAverage(params5) / GetAverage(params6) >= 0.20)
                ||
                (val1 > val2 && GetAverage(params1) / GetAverage(params1) >= 0.75
                && GetAverage(params3) / GetAverage(params4) >= 0.20)
                ||
                (val2 > val1 &&  GetAverage(params1) / GetAverage(params2) >= 0.75
                && GetAverage(paramsparams3) / GetAverage(params4) >= 0.20))
            {
                /// result of validation.
            }

there could be different set of parameters for getting average. is it possible to run these checks in foreach somehow???

thanks for any advice.

Aucun commentaire:

Enregistrer un commentaire