def test_kneighbors_classifier_kneighbors():

    testKNN = MyKNeighborsClassifier()

    train = [[1, 1], [1, 0], [0.33, 0], [0, 0]]
    train_labels = ["bad", "bad", "good", "good"]
    test = [[0.33, 1]]

    testKNN.n_neighbors = 3
    testKNN.X_train = train
    testKNN.y_train = train_labels

    threeDist, threeIndices = testKNN.kneighbors(test)
    expectedDist = [0.670, 1.000, 1.053]
    expectedInd = [0, 2, 3]

    assert np.allclose(threeDist, expectedDist)
    assert np.allclose(threeIndices, expectedInd)

    # case 2
    testKNN = MyKNeighborsClassifier()
    train = [[3, 2], [6, 6], [4, 1], [4, 4], [1, 2], [2, 0], [0, 3], [1, 6]]
    train_labels = ["no", "yes", "no", "no", "yes", "no", "yes", "yes"]
    test = [[2, 3]]

    testKNN.n_neighbors = 3
    testKNN.X_train = train
    testKNN.y_train = train_labels

    threeDist, threeIndices = testKNN.kneighbors(test)
    expectedDist = [1.414, 1.414, 2.000]
    expectedInd = [0, 4, 6]

    assert np.allclose(threeDist, expectedDist)
    assert np.allclose(threeIndices, expectedInd)

    # case 3
    testKNN = MyKNeighborsClassifier()
    train = [[0.8, 6.3], [1.4, 8.1], [2.1, 7.4], [2.6, 14.3], [6.8, 12.6],
             [8.8, 9.8], [9.2, 11.6], [10.8, 9.6], [11.8, 9.9], [12.4, 6.5],
             [12.8, 1.1], [14.0, 19.9], [14.2, 18.5], [15.6, 17.4],
             [15.8, 12.2], [16.6, 6.7], [17.4, 4.5], [18.2, 6.9], [19.0, 3.4],
             [19.6, 11.1]]
    train_labels = [
        -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1
    ]

    testKNN.n_neighbors = 5
    testKNN.X_train = train
    testKNN.y_train = train_labels
    test = [[9.1, 11.0]]

    fiveDist, fiveIndices = testKNN.kneighbors(test)
    expectedDist = [0.608, 1.237, 2.202, 2.802, 2.915]
    expectedInd = [6, 5, 7, 4, 8]

    assert np.allclose(fiveDist, expectedDist)
    assert np.allclose(fiveIndices, expectedInd)
def test_kneighbors_classifier_predict():

    testKNN = MyKNeighborsClassifier()

    train = [[1, 1], [1, 0], [0.33, 0], [0, 0]]
    train_labels = ["bad", "bad", "good", "good"]
    test = [[0.33, 1]]

    testKNN.n_neighbors = 3
    testKNN.X_train = train
    testKNN.y_train = train_labels

    predictions = testKNN.predict(test)
    expected = ['good']

    for i in range(len(predictions)):
        assert predictions[i] == expected[i]

    # case 2
    testKNN = MyKNeighborsClassifier()
    train = [[3, 2], [6, 6], [4, 1], [4, 4], [1, 2], [2, 0], [0, 3], [1, 6]]
    train_labels = ["no", "yes", "no", "no", "yes", "no", "yes", "yes"]
    test = [[2, 3]]

    testKNN.n_neighbors = 3
    testKNN.X_train = train
    testKNN.y_train = train_labels

    predictions = testKNN.predict(test)
    expected = ['yes']

    for i in range(len(predictions)):
        assert predictions[i] == expected[i]

    # case 3
    testKNN = MyKNeighborsClassifier()
    train = [[0.8, 6.3], [1.4, 8.1], [2.1, 7.4], [2.6, 14.3], [6.8, 12.6],
             [8.8, 9.8], [9.2, 11.6], [10.8, 9.6], [11.8, 9.9], [12.4, 6.5],
             [12.8, 1.1], [14.0, 19.9], [14.2, 18.5], [15.6, 17.4],
             [15.8, 12.2], [16.6, 6.7], [17.4, 4.5], [18.2, 6.9], [19.0, 3.4],
             [19.6, 11.1]]
    train_labels = [
        -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1
    ]

    testKNN.n_neighbors = 5
    testKNN.X_train = train
    testKNN.y_train = train_labels
    test = [[9.1, 11.0]]

    predictions = testKNN.predict(test)
    expected = [1]

    for i in range(len(predictions)):
        assert predictions[i] == expected[i]