-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add checks to make sure the numbers in the summary match the computed…
… numbers GitOrigin-RevId: 0934d4508823dfcd4d7c7a5b27c353df4d90f4b3
- Loading branch information
1 parent
1a9f9f0
commit 11fca1f
Showing
5 changed files
with
193 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { SummarizationType, VoteTally } from "../types"; | ||
import { SummaryStats } from "../stats_util"; | ||
import { summaryContainsStats } from "./stats_checker"; | ||
|
||
// Has 5 comments and 60 votes. | ||
const TEST_SUMMARY_STATS = new SummaryStats([ | ||
{ id: "1", text: "hello", voteTalliesByGroup: { "group 0": new VoteTally(10, 20, 30) } }, | ||
{ id: "2", text: "hello" }, | ||
{ id: "3", text: "hello" }, | ||
{ id: "4", text: "hello" }, | ||
{ id: "5", text: "hello" }, | ||
]); | ||
|
||
describe("StatsCheckerTest", () => { | ||
it("should return true for a good summary", () => { | ||
const summary = "There are 60 votes and 5 statements."; | ||
expect( | ||
summaryContainsStats(summary, TEST_SUMMARY_STATS, SummarizationType.VOTE_TALLY) | ||
).toBeTruthy(); | ||
}); | ||
|
||
it("should return false if missing the right statement count", () => { | ||
const summary = "There are 60 votes and 6 statements."; | ||
expect( | ||
summaryContainsStats(summary, TEST_SUMMARY_STATS, SummarizationType.VOTE_TALLY) | ||
).toBeFalsy(); | ||
}); | ||
|
||
it("should return false if missing the right vote count", () => { | ||
const summary = "There are 6 votes and 5 statements."; | ||
expect( | ||
summaryContainsStats(summary, TEST_SUMMARY_STATS, SummarizationType.VOTE_TALLY) | ||
).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Checks a Summary for simple string matches. | ||
|
||
import { SummarizationType } from "../types"; | ||
import { SummaryStats } from "../stats_util"; | ||
|
||
/** | ||
* Checks that a summary contains the numbers from the SummaryStats. | ||
* @param summary the summary to consider | ||
* @param summaryStats the numbers to check that the summary contains | ||
* @param summarizationType the type of summarization done | ||
* @returns true if the summary contains the statistics (not necessarily in the right context) | ||
*/ | ||
export function summaryContainsStats( | ||
summary: string, | ||
summaryStats: SummaryStats, | ||
summarizationType: SummarizationType | ||
): boolean { | ||
if (!summary.includes(`${summaryStats.commentCount} statements`)) { | ||
console.error(`Summary does not contain the correct number of total comments from the | ||
deliberation. commentCount=${summaryStats.commentCount} and summary=${summary}`); | ||
return false; | ||
} | ||
|
||
if ( | ||
summarizationType == SummarizationType.VOTE_TALLY && | ||
!summary.includes(`${summaryStats.voteCount} votes`) | ||
) { | ||
console.error(`Summary does not contain the correct number of total votes from the | ||
deliberation. voteCount=${summaryStats.voteCount} and summary=${summary}`); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters