from __future__ import division, print_function, absolute_import

from nose.plugins.attrib import attr
from nose.tools import assert_raises, raises

import numpy as np
from scipy.stats import norm

from ..npc import (fisher,
                   liptak,
                   tippett)

def test_fisher():
    pvalues = np.linspace(0.05, 0.9, num=5)
    np.testing.assert_almost_equal(fisher(pvalues), 11.11546, 5)
    np.testing.assert_equal(fisher(1), -0.0)
    np.testing.assert_array_less(fisher(10), 0)
    
    
def test_liptak():
    pvalues = np.linspace(0.05, 0.9, num=5)
    np.testing.assert_almost_equal(liptak(pvalues), 0.5728894, 5)
    np.testing.assert_equal(liptak(1), norm.ppf(0))
    np.testing.assert_equal(liptak(10), np.nan)
    

def test_tippett():
    pvalues = np.linspace(0.05, 0.9, num=5)
    np.testing.assert_almost_equal(tippett(pvalues), 0.95, 5)
    np.testing.assert_equal(tippett(1), 0)
    np.testing.assert_equal(tippett(10), -9)


def test_t2p():
    obs = 5
    distr = np.array(range(-10, 11))
    np.testing.assert_equal(t2p(obs, distr, "greater"), 6/21)
    np.testing.assert_equal(t2p(obs, distr, "less"), 16/21)
    np.testing.assert_equal(t2p(obs, distr, "two-sided"), 12/21)
@@ -161,16 +161,53 @@
 y as np%0A
+from numpy.random import RandomState%0A
 from sci
@@ -308,16 +308,64 @@
  tippett
+,%0A                   t2p,%0A                   npc
 )%0A%0Adef t
@@ -1288,12 +1288,838 @@
 ed%22), 12/21)
+%0A    %0A%0Adef test_npc():%0A    prng = RandomState(55)%0A    pvalues = np.linspace(0.05, 0.9, num=5)%0A    distr = prng.uniform(low=0, high=10, size=500).reshape(100, 5)%0A    res = npc(pvalues, distr, %22fisher%22, %22greater%22)%0A    np.testing.assert_almost_equal(res, 0.33)%0A    res = npc(pvalues, distr, %22fisher%22, %22less%22)%0A    np.testing.assert_almost_equal(res, 0.33)%0A    res = npc(pvalues, distr, %22fisher%22, %22two-sided%22)%0A    np.testing.assert_almost_equal(res, 0.31)%0A    res = npc(pvalues, distr, %22liptak%22, %22greater%22)%0A    np.testing.assert_almost_equal(res, 0.35)%0A    res = npc(pvalues, distr, %22tippett%22, %22greater%22)%0A    np.testing.assert_almost_equal(res, 0.25)%0A    res = npc(pvalues, distr, %22fisher%22, %0A        alternatives=np.array(%5B%22less%22,%22greater%22,%22less%22,%0A        %22greater%22,%22two-sided%22%5D))%0A    np.testing.assert_almost_equal(res, 0.38)%0A    

add tests for NPC