Skip to content

Commit 7457230

Browse files
committed
Added out-of-range tests for Highs_getPresolvedColName and Highs_getPresolvedRowName
1 parent 0743bca commit 7457230

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

check/TestCAPI.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ void testNames() {
573573

574574
return_status = Highs_passColName(highs, -1, col_prefix);
575575
assert(return_status == kHighsStatusError);
576-
return_status = Highs_passColName(highs, num_col, col_prefix);
577-
assert(return_status == kHighsStatusError);
578576
return_status = Highs_passRowName(highs, -1, row_prefix);
579577
assert(return_status == kHighsStatusError);
578+
return_status = Highs_passColName(highs, num_col, col_prefix);
579+
assert(return_status == kHighsStatusError);
580580
return_status = Highs_passRowName(highs, num_row, row_prefix);
581581
assert(return_status == kHighsStatusError);
582582

@@ -588,12 +588,12 @@ void testNames() {
588588
return_status = Highs_writeModel(highs, "");
589589
assert(return_status == kHighsStatusError);
590590

591+
char name[5]; // 3 chars prefix, 1 char iCol, 1 char 0-terminator
592+
591593
// Define all column names to be different
592594
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
593-
char name[5]; // 3 chars prefix, 1 char iCol, 1 char 0-terminator
594595
sprintf(name, "%s%" HIGHSINT_FORMAT "", col_prefix, iCol);
595-
const char* name_p = name;
596-
return_status = Highs_passColName(highs, iCol, name_p);
596+
return_status = Highs_passColName(highs, iCol, name);
597597
assert(return_status == kHighsStatusOk);
598598
}
599599
return_status = Highs_writeModel(highs, "");
@@ -602,7 +602,6 @@ void testNames() {
602602
// Check that the columns can be found by name
603603
HighsInt ck_iCol;
604604
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
605-
char name[5];
606605
return_status = Highs_getColName(highs, iCol, name);
607606
assert(return_status == kHighsStatusOk);
608607
return_status = Highs_getColByName(highs, name, &ck_iCol);
@@ -622,10 +621,8 @@ void testNames() {
622621

623622
// Define all row names to be different
624623
for (HighsInt iRow = 0; iRow < num_row; iRow++) {
625-
char name[5]; // 3 chars prefix, 1 char iCol, 1 char 0-terminator
626624
sprintf(name, "%s%" HIGHSINT_FORMAT "", row_prefix, iRow);
627-
const char* name_p = name;
628-
return_status = Highs_passRowName(highs, iRow, name_p);
625+
return_status = Highs_passRowName(highs, iRow, name);
629626
assert(return_status == kHighsStatusOk);
630627
}
631628
return_status = Highs_writeModel(highs, "");
@@ -645,21 +642,17 @@ void testNames() {
645642
assert(return_status == kHighsStatusError);
646643

647644
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
648-
char name[5];
649-
char* name_p = name;
650-
return_status = Highs_getColName(highs, iCol, name_p);
645+
return_status = Highs_getColName(highs, iCol, name);
651646
assert(return_status == kHighsStatusOk);
652647
if (dev_run)
653-
printf("Column %" HIGHSINT_FORMAT " has name %s\n", iCol, name_p);
648+
printf("Column %" HIGHSINT_FORMAT " has name %s\n", iCol, name);
654649
}
655650

656651
for (HighsInt iRow = 0; iRow < num_row; iRow++) {
657-
char name[5];
658-
char* name_p = name;
659-
return_status = Highs_getRowName(highs, iRow, name_p);
652+
return_status = Highs_getRowName(highs, iRow, name);
660653
assert(return_status == kHighsStatusOk);
661654
if (dev_run)
662-
printf("Row %" HIGHSINT_FORMAT " has name %s\n", iRow, name_p);
655+
printf("Row %" HIGHSINT_FORMAT " has name %s\n", iRow, name);
663656
}
664657

665658
// Check extraction of names for the presolved LP, in which the
@@ -671,22 +664,30 @@ void testNames() {
671664
HighsInt presolved_num_row = Highs_getPresolvedNumRow(highs);
672665
assert(presolved_num_col == num_col);
673666
assert(presolved_num_row == num_row-1);
667+
668+
char presolved_name[5];
669+
670+
return_status = Highs_getPresolvedColName(highs, -1, presolved_name);
671+
assert(return_status == kHighsStatusError);
672+
return_status = Highs_getPresolvedRowName(highs, -1, presolved_name);
673+
assert(return_status == kHighsStatusError);
674+
return_status = Highs_getPresolvedColName(highs, presolved_num_col, presolved_name);
675+
assert(return_status == kHighsStatusError);
676+
return_status = Highs_getPresolvedRowName(highs, presolved_num_row, presolved_name);
677+
assert(return_status == kHighsStatusError);
678+
674679
for (HighsInt iCol = 0; iCol < presolved_num_col; iCol++) {
675-
char presolved_name[5];
676-
char* presolved_name_p = presolved_name;
677-
return_status = Highs_getPresolvedColName(highs, iCol, presolved_name_p);
680+
return_status = Highs_getPresolvedColName(highs, iCol, presolved_name);
678681
assert(return_status == kHighsStatusOk);
679682
if (dev_run)
680-
printf("Presolved column %" HIGHSINT_FORMAT " has name %s\n", iCol, presolved_name_p);
683+
printf("Presolved column %" HIGHSINT_FORMAT " has name %s\n", iCol, presolved_name);
681684
}
682685

683686
for (HighsInt iRow = 0; iRow < presolved_num_row; iRow++) {
684-
char presolved_name[5];
685-
char* presolved_name_p = presolved_name;
686-
return_status = Highs_getPresolvedRowName(highs, iRow, presolved_name_p);
687+
return_status = Highs_getPresolvedRowName(highs, iRow, presolved_name);
687688
assert(return_status == kHighsStatusOk);
688689
if (dev_run)
689-
printf("Presolved row %" HIGHSINT_FORMAT " has name %s\n", iRow, presolved_name_p);
690+
printf("Presolved row %" HIGHSINT_FORMAT " has name %s\n", iRow, presolved_name);
690691
}
691692

692693
Highs_destroy(highs);

0 commit comments

Comments
 (0)