当前位置: 首页>>代码示例>>Python>>正文


Python Mock.char_bag方法代码示例

本文整理汇总了Python中unittest.mock.Mock.char_bag方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.char_bag方法的具体用法?Python Mock.char_bag怎么用?Python Mock.char_bag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.char_bag方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_train_pwd_long

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
 def test_train_pwd_long(self):
     config = Mock()
     config.char_bag = string.ascii_lowercase + pg.PASSWORD_END
     m = mm.MarkovModel(config, smoothing='none', order=4)
     m.train([('pa', 1)])
     self.assertEqual(m.freq_dict, {
         'p' : 1, 'pa' : 1, 'pa' + pg.PASSWORD_END : 1
     })
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:10,代码来源:markov_model_tests.py

示例2: test_predict

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
 def test_predict(self):
     config = Mock()
     config.char_bag = pg.PASSWORD_END + 'aehnpst'
     m = mm.MarkovModel(config, smoothing='none', order=2)
     m.train([('pass', 1), ('past', 1), ('ashen', 1)])
     answer = np.zeros((len(config.char_bag), ), dtype=np.float64)
     m.predict('pa', answer)
     np.testing.assert_array_equal(answer, np.array([
         0, 0, 0, 0, 0, 0, 1, 0
     ]))
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:12,代码来源:markov_model_tests.py

示例3: test_train_one

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
 def test_train_one(self):
     config = Mock()
     config.char_bag = (
         string.ascii_lowercase + pg.PASSWORD_END)
     m = mm.BackoffMarkovModel(config, order=2)
     m.train([('pass', 1)])
     self.assertEqual(set(m.freq_dict.items()), set([
         (mm.PASSWORD_START, 1), ('p', 1), ('a', 1), ('s', 2),
         (pg.PASSWORD_END, 1), (mm.PASSWORD_START + 'p', 1),
         ('pa', 1), ('as', 1), ('ss', 1), ('s' + pg.PASSWORD_END, 1)
     ]))
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:13,代码来源:markov_model_tests.py

示例4: test_save_load_model

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
    def test_save_load_model(self):
        config = Mock()
        config.char_bag = string.ascii_lowercase + pg.PASSWORD_END
        m = mm.MarkovModel(config, smoothing='none', order=2)
        m.train([('pass', 1), ('past', 1), ('ashen', 1)])
        self.assertAlmostEqual(m.probability_next_char('', 'p'), 2./3.)

        with tempfile.NamedTemporaryFile('w') as tempf:
            m.saveModel(tempf.name)
            new_model = mm.MarkovModel.fromModelFile(
                tempf.name, config, smoothing='none', order=2)

        self.assertAlmostEqual(new_model.probability_next_char('', 'p'), 2./3.)
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:15,代码来源:markov_model_tests.py

示例5: test_train_one_pwd_no_smoothing

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
    def test_train_one_pwd_no_smoothing(self):
        config = Mock()
        config.char_bag = string.ascii_lowercase + pg.PASSWORD_END
        m = mm.MarkovModel(config, smoothing='none', order=2)
        m.train([('pass', 1)])
        self.assertAlmostEqual(m.probability_next_char('p', 'a'), 1)
        self.assertAlmostEqual(m.probability_next_char('pa', 's'), 1)
        self.assertAlmostEqual(
            m.probability_next_char('pass', pg.PASSWORD_END), .5)
        self.assertAlmostEqual(m.probability_next_char('pas', 's'), .5)
        self.assertAlmostEqual(m.probability_next_char('', 'p'), 1)

        self.assertAlmostEqual(m.probability_next_char('pas', 'k'), 0)
        self.assertAlmostEqual(m.probability_next_char('', 'j'), 0)
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:16,代码来源:markov_model_tests.py

示例6: test_predict_longer_context

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
 def test_predict_longer_context(self):
     config = Mock()
     config.char_bag = ('abc' + pg.PASSWORD_END)
     config.backoff_smoothing_threshold = 0
     config.additive_smoothing_amount = 0
     m = mm.BackoffMarkovModel(config, order=3)
     m.train([('abc', 1), ('aaa', 1)])
     answer = np.zeros((len(config.char_bag), ), dtype=np.float64)
     m.predict('ab', answer)
     np.testing.assert_array_almost_equal(
         answer, np.array([0., 0., 0., 1.], dtype=np.float64))
     answer.fill(0)
     m.predict('ba', answer)
     np.testing.assert_array_almost_equal(
         answer, np.array([.25, .5, .25, 0.], dtype=np.float64))
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:17,代码来源:markov_model_tests.py

示例7: test_train_high_order_no_smoothing

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import char_bag [as 别名]
    def test_train_high_order_no_smoothing(self):
        config = Mock()
        config.char_bag = string.ascii_lowercase + pg.PASSWORD_END
        m = mm.MarkovModel(config, smoothing='none', order=3)
        m.train([('pass', 1), ('past', 1), ('ashen', 1)])
        self.assertAlmostEqual(m.probability_next_char('', 'p'), 2./3.)
        self.assertAlmostEqual(m.probability_next_char('p', 'a'), 1)
        self.assertAlmostEqual(m.probability_next_char('pa', 's'), 1)
        self.assertAlmostEqual(
            m.probability_next_char('pass', pg.PASSWORD_END), 1)
        self.assertAlmostEqual(m.probability_next_char('pas', 's'), 1./3.)
        self.assertAlmostEqual(m.probability_next_char('pas', 't'), 1./3.)
        self.assertAlmostEqual(m.probability_next_char('as', 'h'), 1./3.)
        self.assertAlmostEqual(m.probability_next_char('as', 't'), 1./3.)

        self.assertAlmostEqual(m.probability_next_char('pas', 'k'), 0)
        self.assertAlmostEqual(m.probability_next_char('', 'j'), 0)
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:19,代码来源:markov_model_tests.py


注:本文中的unittest.mock.Mock.char_bag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。