How to unit test this c function? [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a simple c function,
uint_8 tempM_main()
{
if(g_variable1 > g_variable2)
tempM = g_variable1;
else
tempM = g_variable2;
}
where g_variable1 and g_variable2 are the global variable.
How can i able to unit test this scenario?
equivalent class and boundary class need to apply for this?
I am using Tessy tool for unit testing.

It has undefined behavior if you use the return value, because it says it should return an uint_8 but does not return anything. Before it can be tested in a sensible way, this should be corrected. Either via changing the signature or returning a value.
Let's take the case where you have added a return statement. You're obviously using globals, so you can test it like this:
g_variable1 = <value1>
g_variable2 = <value2>
assert(tempM_main() == <value3>);
assert(tempM == <value4>);
If you change the signature to return void, just remove the first assert and replace it with only the function call.

Related

How to use the screen-name value to check a field of a structure In ABAP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I have created a screen in ABAP for a new Infotype. Inside the program, I'm doing a loop screen to get different values, but the most important is to know the value of the field inside of the value of screen-name.
An example
screen-name = 'table-field'
valuefield = screen-name.
**if valuefield is initial.
...
endif.**
How can I do this?
You can dynamically access a screen value by using FIELD-SYMBOLS
screen-name = 'table-field'.
assign (screen-name) to FIELD-SYMBOL(<fs>).
" you must check if the assignement has been done successfully
" before accessing the content
if sy-subrc = 0 and <fs> is initial.
endif.
If your ABAP version does not allow inline declaration you can consider this:
screen-name = 'table-field'.
FIELD-SYMBOLS <fs> type any.
assign (screen-name) to <fs>.
if sy-subrc = 0 and <fs> is initial.
endif.

How can I write an array of arraylist in the uml? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This is my array of arraylist: Arraylist[] a = new Arraylist[SIZE];
I’m struggling with writing it in my UML diagram, how can I write it?
With or without the <>?
The simplest way is to define it this way:
a is of type Arraylist (after the colon) with multiplicity 0..* and its default (after the equal sign) is Arraylist[SIZE].
As commented by #bruno the default value is a bit of interpretation. UML basically should be held language agnostic, but sometimes you just want to point out implementation details (for whatever reason). So you can add the new keyword right in front of the Arraylist[SIZE]. What that actually means is language dependent (and so out of a general scope I like to stick to).

Which code style is better in terms of readability and performance? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am wondering which code style is better for
human readability
program performance
Let's imagine we have 2 functions:
// first one
void foo(void) {
if (error)
exit(1);
....
}
// second one
void bar(void) {
if (!error) {
....
}
else
exit(1);
}
Both of them work in the same way in terms of execution, but which code style is preferable?
If I had to choose out of these two only, I'd choose the first one.
Reason:
It's simple. (does not use any operator like !)
It does not need comments to explain what happens inside.
(self-readable code)
It avoids extra pair of { } which makes the code more readable
Both performs nearly the same, I highly doubt there will be a
difference in performance.
Hence, first one is preferable.

how return keyword work in main function or any user defined function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
what basis that does function return 0 or 1 o especially in main()?
is it possible that -1 is the return value?
By placing void in front of any function definition, you make it so that the function does not need to return a value. For example:
void test(void)
{
...
}
Would not return anything.

Why the const value can be changed using pointer inside the stack.? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
The const value can be changed inside the stack using pointer.But we can not modify the value of a const variable when it is defined globally.Because it goes to the RO data section.So this value is protected.But inside a stack the const variable doesn't provide protection.Why..?..If it is not providing any protection means then what is the use of const value inside the stack.?.
When you use the const keyword you just tell the compiler to throw error when you try to assign this variable, but it doesn't protect memory.

Resources