Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ensure K value in reverseK is at least 1 #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jserv merged 1 commit into sysprog21:master from EricccTaiwan:fix-reverseK
Mar 16, 2025

Conversation

Copy link
Contributor

@EricccTaiwan EricccTaiwan commented Mar 13, 2025
edited
Loading

Passing 0 or a negative value for K does not cause errors, as the input is an integer. However, this behavior may be confusing for users. To improve clarity, enforce K to be an integer greater than or equal to 1 and return an error if the input is invalid.

Change-Id: Ic68c1acbbd45153da8c3d7682d9251eec9ce597f

Before

$ ./qtest
cmd> new
l = []
cmd> it a
l = [a]
cmd> it b
l = [a b]
cmd> reverseK 2
l = [b a]
cmd> reverseK 0
l = [b a]
cmd> reverseK -1
l = [b a]
cmd> free
l = NULL
cmd> quit
Freeing queue
$

After

$ ./qtest
cmd> new
l = []
cmd> it a
l = [a]
cmd> it b
l = [a b]
cmd> reverseK 2
l = [b a]
cmd> reverseK 0
Invalid number of K = '0'
cmd> reverseK -1
Invalid number of K = '-1'
cmd> free
l = NULL
cmd> quit
Freeing queue
$ 

qtest.c Outdated
if (!get_int(argv[1], &k)) {
report(1, "Invalid number of K");
if (!get_int(argv[1], &k) || k < 1) {
report(1, "Invalid number of K = '%s'", argv[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine the error message, addressing the valid range (at least 1).

EricccTaiwan reacted with thumbs up emoji
qtest.c Outdated
if (!get_int(argv[1], &k)) {
report(1, "Invalid number of K");
if (!get_int(argv[1], &k) || k < 1) {
report(1, "Invalid number of K = '%s' (at least 1)", argv[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to print the value when K < 1. Improve the wording.

EricccTaiwan reacted with thumbs up emoji
qtest.c Outdated
if (!get_int(argv[1], &k)) {
report(1, "Invalid number of K");
if (!get_int(argv[1], &k) || k < 1) {
report(1, "Invalid number of K (at least 1)", argv[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check format string.

EricccTaiwan reacted with thumbs up emoji
Passing 0 or a negative value for K does not cause errors, as the input
is an integer. However, this behavior may be confusing for users. To
improve clarity, enforce K to be an integer greater than or equal to 1
and return an error if the input is invalid.
Co-authored-by: Po-Ying Chiu <charlie910417@gmail.com>
Change-Id: I6741888f888523d00f83cd554fc1442e99120a64
@jserv jserv merged commit 1a8b5f4 into sysprog21:master Mar 16, 2025
1 of 2 checks passed
Copy link
Contributor

jserv commented Mar 16, 2025

Thank @EricccTaiwan for contributing!

EricccTaiwan reacted with rocket emoji

@EricccTaiwan EricccTaiwan deleted the fix-reverseK branch March 16, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@jserv jserv jserv left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /