小编avo*_*iva的帖子

试图实现python TestSuite

我有两个测试用例(两个不同的文件),我想在测试套件中一起运行.我可以通过"正常"运行python来运行测试但是当我选择运行python-unit测试时它会说0个测试运行.现在我只想尝试至少进行一次测试才能正确运行.

import usertest
import configtest # first test
import unittest   # second test

testSuite = unittest.TestSuite()
testResult = unittest.TestResult()
confTest = configtest.ConfigTestCase()
testSuite.addTest(configtest.suite())
test = testSuite.run(testResult)
print testResult.testsRun # prints 1 if run "normally"
Run Code Online (Sandbox Code Playgroud)

这是我的测试用例设置的一个例子

class ConfigTestCase(unittest.TestCase):
    def setUp(self):

        ##set up code

    def runTest(self):

        #runs test


def suite():
    """
        Gather all the tests from this module in a test suite.
    """
    test_suite = unittest.TestSuite()
    test_suite.addTest(unittest.makeSuite(ConfigTestCase))
    return test_suite

if __name__ == "__main__":
    #So you can run tests from this module individually. …
Run Code Online (Sandbox Code Playgroud)

python unit-testing regression-testing test-suite python-unittest

28
推荐指数
2
解决办法
3万
查看次数

在VSCode中启动一个新项目

我在这里遇到一些与之相关的问题:

  1. 我正在尝试启动一个新项目,但它一直默认为我已打开的项目.我似乎无法找到一种方法来开始新的项目.

  2. 我无法弄清楚如何从项目中删除文件夹.假设我在项目中添加了错误的文件夹,我想将其删除,我该怎么做?

谢谢

visual-studio-code

19
推荐指数
4
解决办法
3万
查看次数

Angular2 - 使用debounceTime测试调用

我正在使用一个表单控件,使用valueChanges和检测更改debounceTime.我正在编写一个测试间谍itemService来检查update方法是否被调用.如果我debounceTime从表单控件中删除该测试工作正常.

这是组件中的表单控件.

this.itemControl.valueChanges.debounceTime(300).subscribe(response => {
   this.itemService.update(response);
});
Run Code Online (Sandbox Code Playgroud)

这是测试

it('should do stuff',
    inject([ItemService], (itemService) => {
      return new Promise((res, rej) =>{
        spyOn(itemService, 'update');
        let item = {
            test: 'test'
        };
        fixture.whenStable().then(() => {
          let itemControl = new FormControl('test');
          fixture.componentInstance.itemControl = itemControl;
          fixture.autoDetectChanges();

          fixture.componentInstance.saveItem(item);
          expect(itemService.update).toHaveBeenCalled();

})}));
Run Code Online (Sandbox Code Playgroud)

这是组件的saveItem函数

saveItem(item): void {
    this.itemControl.setValue(item);
}
Run Code Online (Sandbox Code Playgroud)

就像我说的,如果我debounceTime从表单控件中删除测试执行正常,但我不能这样做.我已经尝试在tick()通话前添加一个电话,expect但我得到了这个错误

Unhandled Promise rejection: The code should be running in the fakeAsync zone to …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing typescript angular

10
推荐指数
1
解决办法
5938
查看次数

使用 matplotlib 增加饼图大小,radius 参数似乎不起作用

试图把馅饼做大。查看文档和其他地方,它说要设置半径。似乎无论我在半径中放入哪个值都没有增加。我正在发布完整的代码和它生成的图像。

import matplotlib.pyplot as plt


def autopct_generator(limit):
    """Remove percent on small slices."""
    def inner_autopct(pct):
        return ('%.2f%%' % pct) if pct > limit else ''
    return inner_autopct

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs', 'Test', 'Test2', 'Test3', \
    'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10', \
    'Test11', 'Test12', 'Test13', 'Test14'
sizes = [15, 30, 45, 10, 10, 24, 13, 18, 28, 20, 13, 15, 5, 1, 18, 10,
         10, 10]
NUM_COLORS = len(sizes)

fig1, ax1 = plt.subplots(figsize=(6, 5))

# set color theme …
Run Code Online (Sandbox Code Playgroud)

python matplotlib python-2.7 pie-chart

10
推荐指数
1
解决办法
3万
查看次数

在自身内交换对象

我正试图在自己内部交换一个对象.它工作,但当我添加一个析构函数时,它给了我一个双重自由错误.有办法防止这种情况吗?我正在谈论的方法是void swap(SimpleArray &object).

(对不起,如果你在我的帖子中输入了错误的信息之前看过这个...)

#include "TestType.h"
class SimpleArray {

    private: 
        TestType* pArray;
        //TestType* temp;
    public:
        SimpleArray(TestType *array)
        {
            this->pArray = array;
        }
        ~SimpleArray() { delete[] pArray; }
        SimpleArray() { pArray = 0;}
        SimpleArray(const SimpleArray& arg){ pArray = arg.pArray; }
        ~SimpleArray() { delete[] pArray; }
        TestType * get() const{ return pArray; }
        bool isNonNull() const { return pArray != 0; }
        //TestType* pArray;
        void reset(TestType*& p) {this->pArray = p; }
        void reset() { pArray = 0; }

        void swap(SimpleArray …
Run Code Online (Sandbox Code Playgroud)

c++ oop destructor double-free delete-operator

3
推荐指数
1
解决办法
1510
查看次数

如何使用 Javascript 获取麦克风/输入设备的采样率?

当您创建新设备时,AudioContext它将采样率设置为默认输出设备。这是预期的默认行为。有谁知道是否有什么方法可以在Javascript中获取输入设备的采样率?

我们可以在AudioContext的文档中看到它说的是sampleRate

该值通常在 8,000 Hz 到 96,000 Hz 之间;默认值会根据输出设备而有所不同,但采样率 44,100 Hz 是最常见的。如果选项中未包含sampleRate属性,或者在创建音频上下文时未指定选项,则默认使用新上下文的输出设备的首选采样率。

我如何使用它的示例:

const stream = await navigator.mediaDevices.getUserMedia({audio: true, video: false});
const context = new AudioContext();
context.sampleRate // This is the default output device's sample rate. I need the default input sampleRate
Run Code Online (Sandbox Code Playgroud)

我一直在搜索文档和互联网以寻找实现此目的的方法,但没有找到任何有用的东西。感谢任何帮助。

javascript sample-rate audiocontext web-audio-api

2
推荐指数
1
解决办法
2075
查看次数

getline(),delim不按预期工作

我试图用逗号分隔这个字符串作为分隔符.我放了一个字符串"史密斯,鄂尔多斯,威廉",它只输出"威廉"而不是史密斯和鄂尔多斯.这里肯定有什么不对的,我看不到,有人可以帮忙吗?

#include <iostream>
#include <string>
#include <vector>
#include <sstream>

int main() {
    int numScenarios(0);
    int numPapers(0);
    int numWriters(0);
    std::vector<std::string> paperTitles (1);
    std::vector<std::string> paperAuthors (1);
    std::vector<std::string> splitAuthors (1);
    std::string token;
    std::string input;
    std::cin >> numScenarios;
    std::cin >> numPapers >> numWriters; 
    for (int i(0); i < numPapers; ++i) {
        std::getline(std::cin,input);
        std::istringstream iss(input);
        while(getline(iss,token,','));
        {
            std::cout << token << std::endl;
        }
        //paperTitles.push_back(input);
        //input = '\0';
    }
    for (int i(0); i < numWriters; ++i) {
        getline(std::cin,input);
        paperAuthors.push_back(input);
        input = '\0';
    }


return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ split console-application getline

0
推荐指数
1
解决办法
226
查看次数

尝试添加到词典列表时出现NullReferenceException

执行此代码时,我在这些行上得到NullReferenceException:

List<Dictionary<Slot, string>> slots = new List<Dictionary<Slot, string>>();
                Dictionary<Slot, string> somedict = new Dictionary<Slot, string>();
                somedict.Add(new Slot(), "s");
                this.slots.Add(somedict);
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚发生了什么.我用正确的项创建了一个dict,但是当我尝试将它添加到列表中时,我只得到一个NullReferenceException ....

我一直在寻找MSDN和这个网站大约2个小时,但没有运气.谁能帮我吗?我只是想将一个字典存储到一个列表中.

namespace hashtable
{
    class Slot
    {
        string key;
        string value;

        public Slot()
        {
            this.key = null;
            this.value = null;
        }
    }

    class Bucket
    {
        public int count;
        public int overflow;
        public List<Dictionary<Slot, string>> slots;
        Dictionary<Slot, string> somedict;

        public Bucket()
        {
            this.count = 0;
            this.overflow = -1;
            List<Dictionary<Slot, string>> slots = new List<Dictionary<Slot, string>>();
            Dictionary<Slot, string> somedict = new …
Run Code Online (Sandbox Code Playgroud)

.net c# oop dictionary list

0
推荐指数
1
解决办法
4556
查看次数