Questions tagged [assert]

An assertion is a statement, which aborts a program when it evaluates to false. Assert is typically used for debugging and situations which should never happen.

Filter by
Sorted by
Tagged with
0 votes
2 answers
53 views

How to transform TS asserts condition in handy function?

I'm using asserts condition and have a code like this enum Types { a = "a", b = "b", c = "c" } type Entity = { type: Types }; assert(condition: any): asserts condition {...
NtsDK's user avatar
  • 961
-1 votes
1 answer
37 views

pads numbers in file-names in R

i used PadNumbers <- function(numbers) { assertIntegerish(numbers, min.len = 0, lower = 0) strnumbers <- as.character(numbers) numbers <- as.numeric(gsub(".*?(\\d+).*", "\...
tong tong's user avatar
0 votes
0 answers
6 views

Why do declared but uninitialized pointers have a value in code blocks?

Hello I have a problem with pointers in C where I dont really know how codeblocks handles pointers when they are only declared but uninitialized as followed: char *badString; printString(badString); ...
DerBuut's user avatar
1 vote
1 answer
37 views

Why won't my half array test and odd array test work? ( I used assert to debug)

I have been tasked with using a function to print a full array, also a half array, also an array with only odd numbers. I used assert and print statements to debug but I haven't had success. This is ...
Carlos Barrett's user avatar
1 vote
1 answer
31 views

With Rails and Rspec, is there a way to see what page an action really takes you to?

I have a rails test in which I go to a page and enter information, save the page (which takes me back one page), and attempt to come back to see if the data is still there. I am hitting a wall, but ...
wruckie's user avatar
  • 1,739
0 votes
0 answers
32 views

Pytest Assertions are catching the error but the test is not being marked as failed

I'm using PyCharm as IDE, I'm testing some API results using 'assert', the console shows that the assertion is failing, however the test is still displayed as "Passed" with a green checkmark ...
axcha15's user avatar
  • 53
1 vote
2 answers
75 views

Selenium C#: Find element of text of URL with extra '/'

Newbie here with Selenium C# and teaching myself along the way. I have got code and tests running for when I am able to verify a piece of text connected to the URL. Example of what I have got working:...
Kirsty Meredith's user avatar
1 vote
1 answer
103 views

How can I add my own messages about an error in assert() in C?

I need to get an output with the assertion failing like this: Assertion failed! Program: C:\...\assert-test.exe File: C:\...\assert-test.c, Line 21 Expression: denominator != 0.0 Can anyone explain ...
Assel's user avatar
  • 31
2 votes
1 answer
76 views

Python testing assertions (unittest, playwright)

so im new to testing and have been learning python/playwright testing for a couple of weeks now. I've got to assertions and have found multiple ways to write them, so this might sound like a stupid ...
Aleksandar Dostinov's user avatar
0 votes
0 answers
55 views

Assertion Error while creating instance of DeterministicProcesses

Here I attach the traceback of assertion error while creating an object of Deterministic Process, kindly please check and help me out. Here is my code : fourier = CalendarFourier(freq='1D', order=4) #...
Sarvagya Porwal's user avatar
-1 votes
2 answers
57 views

How to Write Assertions for Comparing Datetime Strings with Timezone Offset

I'm working on a Python script that interacts with a server and retrieves datetime strings. The challenge I'm facing is comparing datetime strings from my script with those received from the server. ...
vladandreevza5557's user avatar
-2 votes
2 answers
212 views

Assert that golang slices have equal elements, no matter the order [duplicate]

I have the following assertion in a golang test us.EqualValues(testUnitMergeEnvVars[i].expectedEnvVars, gotValues) where us is a testify/suite.Suite type. This fails with the following message ...
pkaramol's user avatar
  • 16.9k
0 votes
1 answer
71 views

How do I write an assert statement for a vector in C++?

I am creating a user class that has an ID, name, birth year, zip code, and friend's list. I want to verify if the friend's list (which is vector<std::size_t>) got passed into my constructor ...
Hayoung Ryow's user avatar
1 vote
2 answers
23 views

Number in df column, but not in list version of that column

I have the following code: if 0 in df[RATING_COL]: rating_col_list = df[RATING_COL].to_list() assert 0 in rating_col_list The assert is triggering an AssertionError. How can this ...
Pro Q's user avatar
  • 4,524
0 votes
1 answer
64 views

Why does redirecting the output of assert() work when done using freopen() and stderr but not when redirecting the buffer of std::cerr normally?

I'd like to redirect the output that assert() creates when an assertion fails, so that it is written to a log file instead of the output window. I assumed assert() uses std::cerr to output but when ...
JensB's user avatar
  • 911
2 votes
1 answer
94 views

MFC based C++ program assert failed

I wrote a MFC based C++ program, while the release version runs smoothly on the target machine, the debug version can not. it appears assert failed as the following screenshot shows: I need this ...
winston's user avatar
  • 29
1 vote
1 answer
37 views

Usage assert(not <condition>) [duplicate]

Reference: std::is_sorted In the example section of the above link, I see the following usage: int data[] = {3, 1, 4, 1, 5}; assert(not std::is_sorted(std::begin(data), std::end(data))); I am ...
Vinod's user avatar
  • 1,041
-2 votes
1 answer
32 views

How does `containsInAnyOrder` compare items?

I've got a CustomField class and I've overriden the equals and hashcode methods. But when I try to compare 2 lists of CustomField objects, it fails. Why wouldn't the containsInAnyOrder work in the ...
S.Dan's user avatar
  • 1,824
-1 votes
2 answers
380 views

How to use assert module in Ansible?

I want an Ansible code that asserts and checks these two interfaces are not equal: bond_interfaces: [eno5, eno6] node0125.computer.me: management_ip: x.x.x.x management_interface:...
junior person's user avatar
0 votes
0 answers
13 views

Is there any equivalent of Asset.fail(message) in WebdriverIO expect assertions

Is there any equivalent of Asset.fail(message) of TestNG in WebdriverIO expect assertions. I need to explicitly fail the test in catch block by passing the exception error message. I didn't find any ...
mra419's user avatar
  • 413
0 votes
1 answer
57 views

Checking abstract method behavior (the contract) with assertions in Java [closed]

I want the abstract method to be implemented to keep some contract e.g. I have a Cells abstract class which is a wrapper around Cell[], Cells abstract class has abstract protected method _initCells, ...
user502233's user avatar
0 votes
0 answers
22 views

Tests fail due to presence of long literal in output

A few of my tests have an expected response and an actual response. The actual is a response from the DB and it's comparing against a manually built list. The code can be simplified to below: # List ...
Tyler Weaver's user avatar
0 votes
0 answers
20 views

How can I make this program give me a pytest assert which pass?

I have a function ejercicio5 that is supposed to process a list of lists. Each inner list contains elements, and the function should process these elements and create a specific output format. However,...
Gasper34's user avatar
1 vote
1 answer
104 views

Range checking for operator[] with std::vector and std::array in debug mode

I'm writing some numerical C++ where both std::vector and std::array are being used in performance critical parts of the code. Preferably I would like the operator[] to do range checking in debug mode ...
ander's user avatar
  • 11
0 votes
0 answers
30 views

Get actual value that failed an assertion [duplicate]

Is there a way to get assert to show the actual value that failed the assertion on top of listing the line that failed? Is there a way of doing this in pure Python? I have seen in C++ gtest where you ...
heretoinfinity's user avatar
0 votes
0 answers
102 views

How to apply assertions in ROS2 eloquent?

I'm using eloquent and I wanted to add some assertions in my ros2 project. I tried with the classic assert() marco in cpp, but it seems not working very well. I had an assert(false) in my code, but ...
Joachim Zhang's user avatar
1 vote
2 answers
40 views

Weird assert failure after a struct free in C [duplicate]

I am a beginner in C and I encountered this weird assert failure: assuming we have this setup: #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <assert.h> ...
bongadonga's user avatar
1 vote
1 answer
63 views

Most precise type after checking `typeof a === 'object' && a !== null`

I have this assertion function, which checks that the passed value is an object (according to the typeof operator), but excluding null: export function assertIsJavaScriptObjectExceptNull(value: ...
Feuermurmel's user avatar
  • 9,578
0 votes
1 answer
197 views

How to verify URL using Python Selenium

I am beginner in python/selenium and would appreciate yr help with following: I run a test with Social Media icons on website: to check if SM icons exist and if their links are active, which is fine ...
Ela Janowicz's user avatar
1 vote
0 answers
48 views

UE 4.27 Mobile Vulkan Input Attachment Data assert on first subpass

I have an issue with vulkan in Unreal Engine 4.27 on android. Unreals VulkanPipeline.cpp has assertion: if (RemappingInfo.InputAttachmentData.Num()) { // input attachements can't exist in a first ...
DoN1cK's user avatar
  • 605
0 votes
0 answers
370 views

When I try to assert that a function is not called, using mock, why do I get a ``AssertionError: assert None`` error?

So I am writing some unit tests and I want to test that a certain function is not called. Here is a snippet of my code: def persist(...): for key, meta in metadata.items(): if key in ...
ifrj's user avatar
  • 97
0 votes
1 answer
58 views

Selenium c# eventually doesn't Second assert condition

Hi I was wondering where the logic went wrong as in the output selenium is asserting the first Condition, but not looking at second condition if the element displayed is pass or fail. foreach (var ...
user21175930's user avatar
1 vote
5 answers
276 views

How do I assert that a given jq expression is returning only one result?

Say I'm getting an API response back that looks somewhat like this: { "results": [ { "name": "foobar", "description": "it's the foobar ...
strugee's user avatar
  • 2,752
0 votes
1 answer
69 views

assertthat in R with pairlist

I am trying to use assertthat::assert_that() on several conditions to be tested, which are collected in a `pairlist'. The pairlist that I have a looks like this: pairlist_1 <- as.pairlist(alist(is....
dkarlez's user avatar
-1 votes
1 answer
287 views

Can I pass Soft Assert object as a method parameter?

The existing Framework is designed in the below way. We assert a few checks in the VerifyAttributes. Question is I want to change the Assert to soft Assert so the test does not stop on failure of a ...
Divya's user avatar
  • 89
0 votes
2 answers
293 views

How to make rust compiler prevent me from calling a function with an argument value of zero?

Quite simply, I have a setter method on a struct that sets a field value of type i32 and I don't want to allow zero or negative numbers. I have achieved this with an assert! macro like so: pub fn ...
workerjoe's user avatar
  • 2,483
0 votes
3 answers
251 views

Is there any way to write a unit test for a function that uses scanf?

I'm a computer science student, new to C and am trying to write a unit test for this program: Board *get_board_sizes() { int row_count, column_count, mine_count = 0; Board *struct_to_return = (...
asdfg's user avatar
  • 23
0 votes
1 answer
60 views

Dafny: Fail to verify full string by adding characters to string

method AddCharsToString(str: string, len: int, c: char) returns (res: string) requires 0 <= len ensures |res| == len+|str| ensures forall j :: 0 <= j < len ==> res[j] == c ensures ...
1bitcode's user avatar
-1 votes
1 answer
45 views

Function returns correct value when printed but fails assertion

I need to write a code for a pension plan. The main function is such double pensionTarget = 240000; double currentSaving = 0; double annualSalary = 40000; double monthlySaving = 0.1; double ...
Vikraman Arumugam's user avatar
-2 votes
1 answer
78 views

How to ignore fragment of f-string in python assert

Is it possible to ignore one fragment of f-string in python assertion, eg. assert results.to_dict() == { "comment": f"Retrying in 3600 seconds (1/5)", } How to ...
lukos06's user avatar
  • 197
0 votes
2 answers
119 views

How to convert or merge multiple assert statements into one

I have a multiple assert statement in a python test function as below: def test_function(): assert A.a == 1 assert B.b == 2 assert C.c == 3 assert D.d == 4 assert E.e == 5 ...
jhonD's user avatar
  • 39
-1 votes
1 answer
69 views

Symfony Assert\Expression compare entity property with current users property

Is it possible to get current authenticated user object in symfony Assert\Expression ? I want to use something like #[Assert\Expression( this.getType() != user.getType()", message: '...
Rayiez's user avatar
  • 1,450
0 votes
1 answer
298 views

How to use assert in Python production source code?

We are looking at self-developed libraries shared between multiple Django projects or components of the same project, not the published open-source libraries. Question: We wonder whether it is OK to ...
James's user avatar
  • 1,523
-2 votes
1 answer
49 views

java.lang.NumberFormatException: For input string: "488.15 EUR"

I make automation testing and I want extract text from id element( ok I make it using comand getText() is works, text is "488.15 EUR",after I want make operation with this nr ,I want to ...
Catea's user avatar
  • 3
0 votes
1 answer
36 views

how to check does a method throw a exception or not? [duplicate]

How to check does a method throw an exception or not in Junit in @Test field ?? for example: @Test public void testGenerateInvalidStudentData() { //TODO: check does studentIdGenerator.generate(...
ahmad bagheri's user avatar
0 votes
1 answer
81 views

testing a c program that gets user input from the terminal

I am writing a program in c named: "shell" (i mimic a shell), and I want to write some tests to make sure I follow all the test cases, so I tried using #include <assert.h> but I don't ...
Dolev Dublon's user avatar
0 votes
0 answers
67 views

Test failed with java.lang.RuntimeException: assertTrue: expected true, was false

I have the following code: public class Properties { public static void main(String[] args) throws Exception { Files.writeString(Path.of("anything"), "anything"); ...
Navie's user avatar
  • 11
0 votes
2 answers
54 views

AssertionError when normalizing matrix in Python

I have defined the following function in Python to return a normalized version of the matrix M. def get_normalized_matrix(M, O): M_copy = np.copy(M) M_copy[O == 0] = 0 a = np.sum(M_copy) / ...
Rose Ben Ann's user avatar
1 vote
0 answers
53 views

How to write a unit test for IndexError in python

I have a function generate_grid(n, dices) that takes into parameters n and dices, generates a grid of size n-by-n. In my unit tests, I wish to make sure that if I call generate_grid(-4, Dices), It is ...
Lilian.save.it's user avatar
0 votes
1 answer
77 views

XSD: How to make the integer range of a value dependent on other element?

This is the second time I ask this question: In an XML document (using Version 1.1) an element random has two integers: An integer start that normally only should have a range of value from min=1 and ...
Daniel Janz's user avatar

1
2 3 4 5
55