simple 1NN

I'm confused here as i'm unable to figure out why code is not working as expected on entire test data set. Same code works when I use it to predict value of 1 test data.