Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BarcodeStandard/BarcodeLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ private SKBitmap Generate_Image()

break;
}//case
case Type.Jan13:
case Type.Ean13:
{
// Automatically calculate Width if applicable.
Expand Down
15 changes: 9 additions & 6 deletions BarcodeStandard/Symbologies/JAN13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ namespace BarcodeLib.Symbologies
/// JAN-13 encoding
/// Written by: Brad Barnhill
/// </summary>
class JAN13 : BarcodeCommon, IBarcode
internal class JAN13 : BarcodeCommon, IBarcode
Copy link
Owner

Choose a reason for hiding this comment

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

if we mark this symbology as internal shouldnt we mark the others as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if we mark this symbology as internal shouldnt we mark the others as well?

There’s no reason to mark a class in the global scope internal. That is the default visibility. I’d argue to remove internal here instead of adding it.

{
private readonly EAN13 _ean13;

public JAN13(string input)
{
RawData = input;
_ean13 = new EAN13(input);
Copy link
Owner

Choose a reason for hiding this comment

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

instead of initing an EAN13 here wouldnt it be better to expose the check digit method there and call the check digit here in the constructor OR make a copy of the CheckDigit() method in JAN so we get proper error codes here and just calculate it here. This way the init doesnt have to happen which runs the encoding and such till after the data validation is done?

RawData = _ean13.RawData;
}

/// <summary>
/// Encode the raw data using the JAN-13 algorithm.
/// </summary>
Expand All @@ -21,14 +25,13 @@ private string Encode_JAN13()
if (!CheckNumericOnly(RawData))
Error("EJAN13-2: Numeric Data Only");

EAN13 ean13 = new EAN13(RawData);
return ean13.Encoded_Value;
return _ean13.Encoded_Value;
}//Encode_JAN13

#region IBarcode Members

public string Encoded_Value => Encode_JAN13();

#endregion
#endregion IBarcode Members
}
}
}
13 changes: 12 additions & 1 deletion BarcodeStandardTests/Symbologies/Ean13Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ public void EncodeBarcode(string data, string expected)
_barcode.Encode(data);
Assert.AreEqual(expected, _barcode.EncodedValue, $"{_barcode.EncodedType}");
}

[DataTestMethod]
[DataRow("498000356216", "4980003562162")]
[DataRow("4980003562162", "4980003562162")]
[DataRow("493123123123", "4931231231238")]
public void CalculateChecksum(string data, string expected)
{
_barcode.Encode(data);

Assert.AreEqual(expected, _barcode.RawData);
}
}
}
}
14 changes: 13 additions & 1 deletion BarcodeStandardTests/Symbologies/Jan13Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ public class Jan13Tests
[DataRow("498000356216", "10100010110001001000110100011010100111010000101010100111010100001101100110011010100001101100101")]
[DataRow("493456789012", "10100010110100001010001101100010000101001000101010100100011101001110010110011011011001011100101")]
[DataRow("492794729478", "10100010110011011011101100010110011101001000101010110110011101001011100100010010010001110010101")]
[DataRow("493123123123", "10100010110100001001100100100110100001011001101010110110010000101100110110110010000101001000101")]
public void EncodeBarcode(string data, string expected)
{
_barcode.Encode(data);
Assert.AreEqual(expected, _barcode.EncodedValue, $"{_barcode.EncodedType}");
}

[DataTestMethod]
[DataRow("498000356216", "4980003562162")]
[DataRow("4980003562162", "4980003562162")]
[DataRow("493123123123", "4931231231238")]
public void CalculateChecksum(string data, string expected)
{
_barcode.Encode(data);

Assert.AreEqual(expected, _barcode.RawData);
}
}
}
}