diff --git a/src/methods/kfn/kfn.cpp b/src/methods/kfn/kfn.cpp
index 3793829cf24ea0400a5da990192acce51a395d86..00f656cdb63cbaa7f2521e19c522e670e45e9afc 100644
--- a/src/methods/kfn/kfn.cpp
+++ b/src/methods/kfn/kfn.cpp
@@ -17,6 +17,7 @@ using namespace mlpack::neighbor;
 
 // Global Variable of the NSModel object so it can be accessed from all functions
 NSModel<FurthestNS> nsModelObj;
+int trainedDimension = 0;
 
 
 // input:   TreeTypes 	                treeType = TreeTypes::KD_TREE,
@@ -47,23 +48,23 @@ void initAndBuildModel(char const *treeType, char const *algorithm,
         tree = NSModel<FurthestNS>::COVER_TREE;
     else if (strcmp(treeType, "r") == 0)
         tree = NSModel<FurthestNS>::R_TREE;
-    else if (strcmp(treeType, "r-star") == 0)
+    else if (strcmp(treeType, "r_star") == 0)
         tree = NSModel<FurthestNS>::R_STAR_TREE;
     else if (strcmp(treeType, "ball") == 0)
         tree = NSModel<FurthestNS>::BALL_TREE;
     else if (strcmp(treeType, "x") == 0)
         tree = NSModel<FurthestNS>::X_TREE;
-    else if (strcmp(treeType, "hilbert-r") == 0)
+    else if (strcmp(treeType, "hilbert_r") == 0)
         tree = NSModel<FurthestNS>::HILBERT_R_TREE;
-    else if (strcmp(treeType, "r-plus") == 0)
+    else if (strcmp(treeType, "r_plus") == 0)
         tree = NSModel<FurthestNS>::R_PLUS_TREE;
-    else if (strcmp(treeType, "r-plus-plus") == 0)
+    else if (strcmp(treeType, "r_plus_plus") == 0)
         tree = NSModel<FurthestNS>::R_PLUS_PLUS_TREE;
     else if (strcmp(treeType, "vp") == 0)
         tree = NSModel<FurthestNS>::VP_TREE;
     else if (strcmp(treeType, "rp") == 0)
         tree = NSModel<FurthestNS>::RP_TREE;
-    else if (strcmp(treeType, "max-rp") == 0)
+    else if (strcmp(treeType, "max_rp") == 0)
         tree = NSModel<FurthestNS>::MAX_RP_TREE;
     else if (strcmp(treeType, "ub") == 0)
         tree = NSModel<FurthestNS>::UB_TREE;
@@ -92,6 +93,7 @@ void initAndBuildModel(char const *treeType, char const *algorithm,
     nsModelObj.RandomBasis() = (randomBasis == 1);
 
     
+    trainedDimension = reference.n_rows;
     nsModelObj.BuildModel(std::move(reference), size_t(leafSize), searchMode, epsilon);
 }
 
@@ -110,6 +112,14 @@ void searchWithQuery(   float *queryMatArr, SP_integer queryMatSize, SP_integer
                         float **neighborsMatArr, SP_integer *neighborsMatColNum, SP_integer *neighborsMatRowNum,
                         float **distancesMatArr, SP_integer *distancesMatColNum, SP_integer *distancesMatRowNum)
 {
+    if (trainedDimension != queryMatRowNum)
+    {
+        std::ostringstream stream;
+        stream << "Queryset has Dim(" << queryMatRowNum << ") but the Referenceset has Dim(" << trainedDimension << ")";
+        raisePrologSystemExeption(stream.str().c_str());
+        return;
+    }
+    
     // convert the Prolog array to arma::mat
     mat query = convertArrayToMat(queryMatArr, queryMatSize, queryMatRowNum);
 
@@ -162,4 +172,4 @@ void searchNoQuery(     SP_integer k,
     // return the Matrices
     returnMatrixInformation(neighborsReturnMat, neighborsMatArr, neighborsMatColNum, neighborsMatRowNum);
     returnMatrixInformation(distancesReturnMat, distancesMatArr, distancesMatColNum, distancesMatRowNum);
-}
\ No newline at end of file
+}
diff --git a/src/methods/kfn/kfn.pl b/src/methods/kfn/kfn.pl
index 838df2d407e7579a0bd61c55121abbb8d58064df..21fc2b8fc0e25fe37af85755db7f8f6286d73b31 100644
--- a/src/methods/kfn/kfn.pl
+++ b/src/methods/kfn/kfn.pl
@@ -21,7 +21,7 @@
 
 
 %% --Input--
-%%              string  treeType        => "kd", "vp", "rp", "max-rp", "ub", "cover", "r", "r-star", "x", "ball", "hilbert-r", "r-plus", "r-plus-plus", "spill", "oct",
+%%              string  treeType        => "kd", "vp", "rp", "max_rp", "ub", "cover", "r", "r_star", "x", "ball", "hilbert_r", "r_plus", "r_plus_plus", "oct",
 %%              string  searchMode      => "naive", "single_tree", "dual_tree", "greedy",
 %%              bool    randomBasis     => (1)true / (0)false,
 %%              int     leafSize        => 20,
@@ -34,6 +34,8 @@
 %%              Initialize the Model and build it.
 %%
 initAndBuildModel(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, ReferenceList, ReferenceRows) :-
+        LeafSize >= 1,
+        Epsilon >= 0,
         convert_list_to_float_array(ReferenceList, ReferenceRows, array(Xsize, Xrownum, X)),
         initAndBuildModelI(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, X, Xsize, Xrownum).
 
@@ -55,6 +57,7 @@ foreign(initAndBuildModel, c, initAndBuildModelI(+string, +string,
 %%              Perform neighbor search on the queryset.
 %%
 searchWithQuery(QueryList, QueryRows, K, NeighborsList, YCols, DistancesList, ZCols) :-
+        K > 0,
         convert_list_to_float_array(QueryList, QueryRows, array(Xsize, Xrownum, X)),
         searchWithQueryI(X, Xsize, Xrownum, K, Y, YCols, YRows, Z, ZCols, ZRows),
         convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList),
@@ -78,6 +81,7 @@ foreign(searchWithQuery, c, searchWithQueryI(   +pointer(float_array), +integer,
 %%              Perform monochromatic neighbor search.
 %%
 searchNoQuery(K, NeighborsList, YCols, DistancesList, ZCols) :-
+        K > 0,
         searchNoQueryI(K, Y, YCols, YRows, Z, ZCols, ZRows),
         convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList),
         convert_float_array_to_2d_list(Z, ZCols, ZRows, DistancesList).
diff --git a/src/methods/kfn/kfn_test.pl b/src/methods/kfn/kfn_test.pl
index 3e74176831b05961006cbc22c88d4793f6206df5..035a06a882681846a8cc8c030d8eb9f78ba9086f 100644
--- a/src/methods/kfn/kfn_test.pl
+++ b/src/methods/kfn/kfn_test.pl
@@ -7,97 +7,203 @@
 :- use_module('../../helper_files/helper.pl').
 
 reset_Model :-
-        initModel(1,0,50,0.0001).
+        initAndBuildModel(kd, dual_tree, 0, 20, 0.0, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
 
 %%
-%% TESTING predicate initAndBuildModel/7
+%% TESTING predicate initAndBuildModel/9
 %%
 :- begin_tests(initAndBuildModel).      
 
 %% Failure Tests
                                             
-test(testDescription, [error(domain_error('expectation' , culprit), _)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, culprit, 50, 0.0001, _).
+test(kfn_InitAndBuildModel_Wrong_TreeType_Input, [error(domain_error('The given TreeType is unknown!' , wrongInput), _)]) :-
+        initAndBuildModel(wrongInput, dual_tree, 0, 20, 0.0, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
 
-test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,1,0,2], 2, perceptron, 50, 0.0001, _).
+test(kfn_InitAndBuildModel_Wrong_SearchMode_Input, [error(domain_error('The given SearchMode is unknown!' , wrongInput), _)]) :-
+        initAndBuildModel(kd, wrongInput, 0, 20, 0.0, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_Negative_LeafSize, fail) :-
+        initAndBuildModel(kd, dual_tree, 0, 0, 0.0, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_Negative_Epsilon, fail) :-
+        initAndBuildModel(kd, dual_tree, 0, 20, -1.0, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
         
 
 %% Successful Tests
 
-test(testDescription3, [true(Error =:= 1)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, perceptron, 50, 0.0001, Error).
-
-test(testDescription4, [true(Error =:= 0.9797958971132711)]) :-
-        reset_Model_No_Train(perceptron),
+test(kfn_InitAndBuildModel_KD) :-
+        initAndBuildModel(kd, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(kd, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(kd, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(kd, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_VP) :-
+        initAndBuildModel(vp, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(vp, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(vp, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(vp, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_RP) :-
+        initAndBuildModel(rp, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(rp, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(rp, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(rp, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_MAX_RP) :-
+        initAndBuildModel(max_rp, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(max_rp, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(max_rp, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(max_rp, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_UB) :-
+        initAndBuildModel(ub, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ub, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ub, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ub, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_COVER) :-
+        initAndBuildModel(cover, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(cover, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(cover, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(cover, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_R) :-
+        initAndBuildModel(r, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_R_STAR) :-
+        initAndBuildModel(r_star, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_star, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_star, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_star, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_X) :-
+        initAndBuildModel(x, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(x, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(x, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(x, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_BALL) :-
+        initAndBuildModel(ball, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ball, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ball, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(ball, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_Hilbert_R) :-
+        initAndBuildModel(hilbert_r, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(hilbert_r, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(hilbert_r, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(hilbert_r, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_R_Plus) :-
+        initAndBuildModel(r_plus, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_R_Plus_Plus) :-
+        initAndBuildModel(r_plus_plus, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus_plus, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus_plus, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(r_plus_plus, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_OCT) :-
+        initAndBuildModel(oct, naive, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(oct, single_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(oct, dual_tree, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3),
+        initAndBuildModel(oct, greedy, 0, 20, 0.005, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3).
+
+test(kfn_InitAndBuildModel_CSV_Input) :-
+        reset_Model,
         open('src/data_csv/iris2.csv', read, File),
         take_csv_row(File, skipFirstRow,10, Data),
-        train(Data, 4, [0,1,0,1,1,0,1,1,1,0], 2, perceptron, 50, 0.0001, Error).
+        initAndBuildModel(kd, dual_tree, 1, 20, 0.005, Data, 4).
 
 :- end_tests(initAndBuildModel).
 
 
+
 %%
 %% TESTING predicate searchWithQuery/7
 %%
 :- begin_tests(searchWithQuery).      
 
 %% Failure Tests
-                                            
-test(testDescription, [error(domain_error('expectation' , culprit), _)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, culprit, 50, 0.0001, _).
-
-test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,1,0,2], 2, perceptron, 50, 0.0001, _).
+                                   
+test(kfn_SearchWithQuery_Wrong_Query_Dims, [error(_,system_error('Queryset has Dim(4) but the Referenceset has Dim(3)'))]) :-
+        reset_Model,
+        searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, 2, _, _, _, _).
+
+test(kfn_SearchWithQuery_Negative_K, fail) :-
+        reset_Model,
+        searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, -1, _, _, _, _).
+
+test(kfn_SearchWithQuery_Too_Large_K, [error(_,system_error('Requested value of k (10) is greater than the number of points in the reference set (4)'))]) :-
+        reset_Model,
+        searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 10, _, _, _, _).
         
 
 %% Successful Tests
 
-test(testDescription3, [true(Error =:= 1)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, perceptron, 50, 0.0001, Error).
+test(kfn_SearchWithQuery_Normal) :-
+        reset_Model,
+        searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 2, NeighborsList, _, DistancesList, _),
+        print('\nNeighbors: '),
+        print(NeighborsList),
+        print('\nDistances: '),
+        print(DistancesList).
 
-test(testDescription4, [true(Error =:= 0.9797958971132711)]) :-
-        reset_Model_No_Train(perceptron),
+test(kfn_SearchWithQuery_CSV_Input) :-
         open('src/data_csv/iris2.csv', read, File),
         take_csv_row(File, skipFirstRow,10, Data),
-        train(Data, 4, [0,1,0,1,1,0,1,1,1,0], 2, perceptron, 50, 0.0001, Error).
+        initAndBuildModel(kd, dual_tree, 0, 20, 0.0, Data, 4),
+        searchWithQuery([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, 7, NeighborsList, _, DistancesList, _),
+        print('\nNeighbors: '),
+        print(NeighborsList),
+        print('\nDistances: '),
+        print(DistancesList).
 
 :- end_tests(searchWithQuery).
 
 
+
 %%
-%% TESTING predicate searchNoQuery/5
+%% TESTING predicate searchNoQuery/10
 %%
 :- begin_tests(searchNoQuery).      
 
 %% Failure Tests
                                             
-test(testDescription, [error(domain_error('expectation' , culprit), _)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, culprit, 50, 0.0001, _).
+test(kfn_SearchNoQuery_Negative_K, fail) :-
+        reset_Model,
+        searchNoQuery(-1, _, _, _, _).
 
-test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,1,0,2], 2, perceptron, 50, 0.0001, _).
+test(kfn_SearchNoQuery_Too_Large_K, [error(_,system_error('Requested value of k (15) is greater than the number of points in the reference set (4)'))]) :-
+        reset_Model,
+        searchNoQuery(15, _, _, _, _).
         
 
 %% Successful Tests
 
-test(testDescription3, [true(Error =:= 1)]) :-
-        reset_Model_No_Train(perceptron),
-        train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, perceptron, 50, 0.0001, Error).
+test(kfn_SearchNoQuery_Normal) :-
+        reset_Model,
+        searchNoQuery(2, NeighborsList, _, DistancesList, _),
+        print('\nNeighbors: '),
+        print(NeighborsList),
+        print('\nDistances: '),
+        print(DistancesList).
 
-test(testDescription4, [true(Error =:= 0.9797958971132711)]) :-
-        reset_Model_No_Train(perceptron),
+test(kfn_SearchNoQuery_CSV_Input) :-
         open('src/data_csv/iris2.csv', read, File),
         take_csv_row(File, skipFirstRow,10, Data),
-        train(Data, 4, [0,1,0,1,1,0,1,1,1,0], 2, perceptron, 50, 0.0001, Error).
+        initAndBuildModel(kd, dual_tree, 0, 20, 0.0, Data, 4),
+        searchNoQuery(7, NeighborsList, _, DistancesList, _),
+        print('\nNeighbors: '),
+        print(NeighborsList),
+        print('\nDistances: '),
+        print(DistancesList).
 
 :- end_tests(searchNoQuery).