Skip to content
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

Damm algorithm #114

Closed
iluwatar opened this issue Oct 19, 2021 · 5 comments
Closed

Damm algorithm #114

iluwatar opened this issue Oct 19, 2021 · 5 comments

Comments

@iluwatar
Copy link
Owner

In error detection, the Damm algorithm is a check digit algorithm that detects all single-digit errors and all adjacent transposition errors.

https://en.wikipedia.org/wiki/Damm_algorithm

@stale
Copy link

stale bot commented Feb 2, 2023

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Feb 2, 2023
@AddeusExMachina
Copy link
Contributor

Hi, I implemented three snippets of the Damm algorithm validation.

  1. Traditional for loop
  boolean damm(String s) {
    int row = 0;
    for (int i = 0; i < s.length(); i++) {
      row = table[row][s.charAt(i) - '0'];
    }
    return row == 0;
  }
  1. Enhanced for loop
  boolean damm(String s) {
    int row = 0;
    for (var c : s.toCharArray()) {
      row = table[row][c - '0'];
    }
    return row == 0;
  }
  1. Stream
  boolean damm(String s) {
    return s.chars().reduce(0, (row, col) -> table[row][col - '0']) == 0;
  }

@stale
Copy link

stale bot commented May 2, 2023

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

Copy link

stale bot commented May 23, 2024

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

@nour-awad
Copy link
Contributor

@iluwatar can you assign me to this issue?

@iluwatar iluwatar moved this from Todo to In Progress in Java Design Patterns project Dec 9, 2024
iluwatar pushed a commit that referenced this issue Dec 14, 2024
* Add unit tests for DammSnippet class

- Implement tests for calculating checksum digits for String, int, and long inputs.
- Add tests for generating full numbers with checksums and validating them.
- Ensure proper handling of invalid inputs (empty string, non-digit characters).
- Include tests for both valid and invalid checksum scenarios.
- Verify functionality for different data types: String, int, and long.

These tests improve coverage and ensure that the Damm algorithm implementation behaves as expected.

* Edited the DammSnippetTest file to pass the build-and-analyze test
@github-project-automation github-project-automation bot moved this from In Progress to Done in Java Design Patterns project Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants