from __future__ import absolute_import, division, print_function

import unittest
import numpy as np

from cleverhans.attacks import VirtualAdversarialMethod


class TestVirtualAdversarialMethod(unittest.TestCase):
    def setUp(self):
        import tensorflow as tf
        import tensorflow.contrib.slim as slim

        def dummy_model(x):
            net = slim.fully_connected(x, 600)
            return slim.fully_connected(net, 10, activation_fn=None)

        self.sess = tf.Session()
        self.sess.as_default()
        self.model = tf.make_template('dummy_model', dummy_model)
        self.attack = VirtualAdversarialMethod(self.model, sess=self.sess)

        # initialize model
        with tf.name_scope('dummy_model'):
            self.model(tf.placeholder(tf.float32, shape=(None, 1000)))
        self.sess.run(tf.initialize_all_variables())

    def test_parse_params(self):
        self.attack.parse_params()
        # test default values
        self.assertEqual(self.attack.eps, 2.0)
        self.assertEqual(self.attack.num_iterations, 1)
        self.assertEqual(self.attack.xi, 1e-6)
        self.assertEqual(self.attack.clip_min, None)
        self.assertEqual(self.attack.clip_max, None)

    def test_generate_np(self):
        x_val = np.random.rand(100, 1000)
        perturbation = self.attack.generate_np(x_val) - x_val
        perturbation_norm = np.sqrt(np.sum(perturbation**2, axis=1))
        # test perturbation norm
        self.assertTrue(np.allclose(perturbation_norm, self.attack.eps))


if __name__ == '__main__':
    # t = TestVirtualAdversarialMethod("test_generate_np")
    # t.test_generate_np()
    unittest.main()

@@ -1554,94 +1554,8 @@
 _':%0A
-    # t = TestVirtualAdversarialMethod(%22test_generate_np%22)%0A    # t.test_generate_np()%0A
     

remove unused comments from test_attacks.py