标签: testing

C# 递归查找最大值(最快)

我对此没有什么想法。我自己最初尝试过,然后从 SO 和 google 复制,它适用于除一个之外的所有情况,但是仍然没有找到一种对于我的作业中的特定测试用例来说足够快的递归算法:/

无论如何,为什么会这样:

        public static int FindMaximum(int[] array)
        {
            if (array is null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            if (array.Length == 0)
            {
                throw new ArgumentException(null);
            }

            return FindMaxRec(array, array.Length);
        }

        public static int FindMaxRec(int[] arr, int n)
        {
            if (n == 1)
            {
                return arr[0];
            }

            return Math.Max(arr[n - 1], FindMaxRec(arr, n - 1));
        }
Run Code Online (Sandbox Code Playgroud)

不适用于此TestCase?:

        [Test]
        [Order(0)]
        [Timeout(5_000)]
        public void FindMaximum_TestForLargeArray()
        {
            int expected = this.max;
            int actual = FindMaximum(this.array);
            Assert.AreEqual(expected, actual);
        } …
Run Code Online (Sandbox Code Playgroud)

c# arrays testing recursion max

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

无法在 Jest 中模拟 jwt-decode

出于测试目的,我需要模拟 jwt-decode 函数,但我在这里找到的建议都没有帮助。使用 jwtDecode 的代码如下所示

 import jwtDecode from 'jwt-decode';
 ...
 const { exp } = jwtDecode(accessToken);
Run Code Online (Sandbox Code Playgroud)

在测试中我需要模拟这个返回exp值。我尝试按照Mock jwt-decode in Jest中的建议来模拟它

jest.mock('jwt-decode', () => () => ({ exp: 123456 }));
const { exp } = jwtDecode('123456');
Run Code Online (Sandbox Code Playgroud)

但这会返回

InvalidTokenError:指定的令牌无效:无法读取未定义的属性“替换”

testing mocking typescript ts-jest

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

RSpec 的 contains_exactly 的哈希值是多少?

我需要验证哈希的内容,我惊讶地发现 RSpeccontain_exactly只适用于数组。理想的期望是:

expect(type.values.values).to contain_exactly(
  ONE: an_object_having_attributes(value: 'uno'),
  TWO: an_object_having_attributes(value: 'dos')
)
Run Code Online (Sandbox Code Playgroud)

基本要求是contain_exactly要求数组包含这些元素,并且哈希等效项必须仅包含指定的确切键/值对。

有很多解决方法都可以

  • include(key: value),但这允许其他键,我需要完全匹配。
  • expect(hash.keys).to contain_exactly(...)但这并不能验证键是否专门链接到值。
  • 无论如何使用contain_exactly(将哈希读取为元组[key, value])并基于子数组进行匹配,例如contain_exactly(a_collection_containing_exactly('ONE', an_object_having_attributes(value: 'uno')), ...)
  • 迭代哈希并根据预期输入将键与值进行匹配aggregate_failures

等等,但我最好奇是否有内置的 RSpec 方法可以做到这一点。

ruby testing rspec ruby-hash

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

Paratest,可以测试特定功能吗?

我使用此命令对用户模块运行测试

./vendor/bin/paratest -pauto modules/User
Run Code Online (Sandbox Code Playgroud)

运行 module/User/Tests 文件夹中的每个测试

我想在模块/用户/测试文件中的特定文件中运行特定函数

路径为:modules/User/Tests/UserTest.php

我要测试的功能是:

function testUserSearch() { }
Run Code Online (Sandbox Code Playgroud)

我只想测试 testUserSearch

有没有办法使用 paratest 来做到这一点?

testing phpunit unit-testing laravel

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

具有不确定数量的键的映射向量的 Clojure 规范

我正在尝试为一个函数编写一个 clojure 规范,该函数采用以下两个映射作为参数。

{1 BL0-MD0-SU, 0 BL0-SM0-SU}
{0 [https://gateway.pinata.cloud/ipfs/QmcLjsUDHVuy8GPUPmj4ZdGa3FWTfGnsKhWZ4dxqUaGGXk/doge.jpg ], 1 [https://gateway.pinata.cloud/ipfs/QmcLjsUDHVuy8GPUPmj4ZdGa3FWTfGnsKhWZ4dxqUaGGXk/doge.jpg ]}
Run Code Online (Sandbox Code Playgroud)

每张地图的长度可以不同,具体取决于用户希望购买多少件 T 恤。我不确定如何为此编写规范,以允许每个映射中的键和值的数量发生变化。如果我可以断言每个映射都包含相同数量的键,那也会很有用。

编辑:

当以下内容通过时,规范也应该通过:

{1 BL0-MD0-SU, 0 BL0-SM0-SU, 2 BL0-LG0-SU}
{0 [https://gateway.pinata.cloud/ipfs/QmcLjsUDHVuy8GPUPmj4ZdGa3FWTfGnsKhWZ4dxqUaGGXk/doge.jpg ], 1 [https://gateway.pinata.cloud/ipfs/QmcLjsUDHVuy8GPUPmj4ZdGa3FWTfGnsKhWZ4dxqUaGGXk/doge.jpg ], 2 [ ]}
Run Code Online (Sandbox Code Playgroud)

testing specifications clojure leiningen clojure.spec

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

如何在 Playwright UI 测试中选择自定义下拉选项

我正在进行端到端 UI 测试,当我尝试为 Harmony Web UI 组件 (<ext-support_he-select>) 选择一个选项时,playwright 无法识别 customere 标签,并且错误提示不是选择选项。

我也无法使用无头录音机记录下拉选择选项,如果有人遇到过此类问题,请告诉我。

HTML 选择代码: { <ext-support_he-select id="workspace-dropdown" class="basic-dropdown basic-workspace-dropdown 低于有效" aria-labelledby="workspace-label" role="combobox" current-value= “” aria-controls =“” aria-disabled =“假” aria-expanded =“假” aria-haspopup =“列表框” tabindex =“0”位置=“下方” aria-activedescendant =“选项14”>

    <ext-support_he-option selected="" value="" aria-selected="true" class="selected" role="option" id="option-14" aria-posinset="1" aria-setsize="9"> Select a Workspace </ext-support_he-option>
  
         
    <ext-support_he-option value="accountPlans" aria-selected="false" role="option" id="option-15" aria-posinset="2" aria-setsize="9"> Account Plans </ext-support_he-option>
   
    <ext-support_he-option value="accounts" aria-selected="false" role="option" id="option-16" aria-posinset="3" aria-setsize="9"> Accounts </ext-support_he-option>
   
    <ext-support_he-option value="contacts" aria-selected="false" role="option" id="option-17" aria-posinset="4" aria-setsize="9"> Contacts </ext-support_he-option> …
Run Code Online (Sandbox Code Playgroud)

html testing ui-testing playwright playwright-test

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

我想将我自己的随机函数与 std::shuffle 一起使用,但它不起作用

当我使用 myRand::RandInt 而不是 default_random_engine 之类的东西时,出现错误。但我不明白我应该如何实现 random_engine 函数。我所做的与 std::random_shuffle 配合得很好,但我知道这个函数已被弃用,而 std::shuffle 是首选。

我正在努力让它发挥作用:

int main()
{
    std::vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

    std::shuffle (v.begin(), v.end(), myRand::RandInt);
  
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我定义了一个命名空间来实现这些功能:

namespace myRand {
    bool simulatingRandom = false;
    std::vector<int> secuenciaPseudoRandom = {1,0,1,0};
    long unsigned int index = 0;
    
    int Rand() {
        //check
        if (index > secuenciaPseudoRandom.size() - 1 ) {
            index = 0;
            std::cout << "Warning: myRand resetting secuence" << std::endl;
        };
        
        if (simulatingRandom) …
Run Code Online (Sandbox Code Playgroud)

c++ testing

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

DUnitX 整数测试始终为真

我有一个这样定义的测试:

[Test]
 [TestCase('TestSetAsInteger 001.', '0')]
 [TestCase('TestSetAsInteger 002.', '666')]
 procedure TestSetAsInteger(IntVal : integer);
Run Code Online (Sandbox Code Playgroud)

并像这样实现:

procedure TTestKeyValueList.TestSetAsInteger(IntVal: integer);
begin
  FKVL.AsInteger['testkey'] := IntVal;
  Assert.AreEqual(IntVal, FKVL.AsInteger['testkey']);
end;
Run Code Online (Sandbox Code Playgroud)

FKVL 中的方法是存根,因此它们应该失败。问题是,他们总是过去。

现在,如果我将测试实现更改为:

procedure TTestKeyValueList.TestSetAsInteger(IntVal: integer);
begin
  FKVL.AsInteger['testkey'] := IntVal;
  Sleep(1);  //This can be anything really, I can call FKVL.Count or other some such
  Assert.AreEqual(IntVal, FKVL.AsInteger['testkey']);
end;
Run Code Online (Sandbox Code Playgroud)

现在测试按预期进行。诡异的。我在这里做错了什么吗?

delphi testing dunitx

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

Haskell解释器,不知道如何运行和测试它

我正在将解释器作为项目任务来工作,为了了解我必须做什么,我决定从互联网下载解释器并运行它。我在WinGhci中启动了指定的文件夹,但我不知道如何测试它以及做什么,你能帮忙吗?

这是文件夹位置的链接。 https://github.com/kseo/poly

其代码的实现在《Write you a Haskell》一书第7章中

.我不知道如何测试它以及做什么,你能帮忙吗?

testing monads interpreter haskell functional-programming

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

Cypress 断言:当 cy.get() 匹配多个元素时,行为是什么?

我无法找到解释赛普拉斯断言在cy.get()匹配多个元素时如何工作的文档。例如:

标记:

<div>
  <button>one</button>
  <button class='green'>two</button>
  <button disabled>three</button>
</div>
Run Code Online (Sandbox Code Playgroud)

测试:

cy.get('button').should('be.disabled');
Run Code Online (Sandbox Code Playgroud)

赛普拉斯是否断言:

  1. 第一个匹配的元素通过?
  2. 所有匹配的元素都通过了吗?
  3. 至少有一个要素通过了?

根据经验,我猜测这是选项 3,但我无法在文档中找到明确解决的问题。

然而

cy.get('button').click();
Run Code Online (Sandbox Code Playgroud)

点击...只有第一个按钮?他们全部?

关于断言,恐怕我们无意中编写了在我们的选择器偶然匹配多个元素并且其中一个元素恰好与断言标准匹配的情况下通过的测试。

显然,通过编写良好的选择器,或者如果我们希望返回多个元素,或者如果我们想显式断言多个元素,或者使用 or ,可以避免这种情况。我主要是寻找对行为的确认,以便我了解 Cypress 在选择多个元素(有意或无意)的情况下如何工作。.first().last().each()

html testing cypress

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