Novel Linearity Tests With Applications To Lattices And Learning Problems