cargo fmt

This commit is contained in:
Henry Schimke
2022-12-15 13:24:07 -06:00
parent c167442e5b
commit 919826b3ec
14 changed files with 417 additions and 274 deletions

View File

@@ -1,69 +0,0 @@
/*
* Copyright (C) 2010 ZXing authors
*
* 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.
*/
package com.google.zxing.oned.rss.expanded;
import java.util.ArrayList;
import java.util.List;
/**
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
*/
final class ExpandedRow {
private final List<ExpandedPair> pairs;
private final int rowNumber;
ExpandedRow(List<ExpandedPair> pairs, int rowNumber) {
this.pairs = new ArrayList<>(pairs);
this.rowNumber = rowNumber;
}
List<ExpandedPair> getPairs() {
return this.pairs;
}
int getRowNumber() {
return this.rowNumber;
}
boolean isEquivalent(List<ExpandedPair> otherPairs) {
return this.pairs.equals(otherPairs);
}
@Override
public String toString() {
return "{ " + pairs + " }";
}
/**
* Two rows are equal if they contain the same pairs in the same order.
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof ExpandedRow)) {
return false;
}
ExpandedRow that = (ExpandedRow) o;
return this.pairs.equals(that.pairs);
}
@Override
public int hashCode() {
return pairs.hashCode();
}
}

View File

@@ -24,7 +24,10 @@
* http://www.piramidepse.com/
*/
use crate::oned::rss::expanded::{binary_util, decoders::{AbstractExpandedDecoder, abstract_expanded_decoder::createDecoder}};
use crate::oned::rss::expanded::{
binary_util,
decoders::{abstract_expanded_decoder::createDecoder, AbstractExpandedDecoder},
};
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
@@ -33,7 +36,7 @@ use crate::oned::rss::expanded::{binary_util, decoders::{AbstractExpandedDecoder
pub const numeric10: &str = "..X..XX";
pub const numeric12: &str = "..X.X.X";
pub const numeric1FNC1: &str = "..XXX.X";
// static final String numericFNC11 = "XXX.XXX";
// static final String numericFNC11 = "XXX.XXX";
pub const numeric2alpha: &str = "....";
@@ -61,7 +64,7 @@ pub const compressedDateEnd: &str = "X..X.XX.........";
pub fn assertCorrectBinaryString(binaryString: &str, expectedNumber: &str) {
let binary = binary_util::buildBitArrayFromStringWithoutSpaces(binaryString).expect("built");
let mut decoder = createDecoder(&binary).expect("get decoder");
let result = decoder.parseInformation().expect("information exists");
assert_eq!(expectedNumber, result);

View File

@@ -26,7 +26,10 @@
use crate::{common::BitArray, Exceptions};
use super::{GeneralAppIdDecoder, AnyAIDecoder, AI01AndOtherAIs, AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder};
use super::{
AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
AI01AndOtherAIs, AnyAIDecoder, GeneralAppIdDecoder,
};
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
@@ -55,43 +58,99 @@ pub trait AbstractExpandedDecoder {
// fn new(information:&BitArray) -> Self where Self:Sized;
}
pub fn createDecoder<'a>( information:&'a BitArray) -> Result<Box<dyn AbstractExpandedDecoder + 'a>,Exceptions>{
if information.get(1) {
return Ok(Box::new(AI01AndOtherAIs::new(information)))
}
if !information.get(2) {
return Ok(Box::new( AnyAIDecoder::new(information)));
}
pub fn createDecoder<'a>(
information: &'a BitArray,
) -> Result<Box<dyn AbstractExpandedDecoder + 'a>, Exceptions> {
if information.get(1) {
return Ok(Box::new(AI01AndOtherAIs::new(information)));
}
if !information.get(2) {
return Ok(Box::new(AnyAIDecoder::new(information)));
}
// let gen_decode = GeneralAppIdDecoder::new(information);
// let gen_decode = GeneralAppIdDecoder::new(information);
let fourBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
let fourBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
match fourBitEncodationMethod {
4=> return Ok(Box::new( AI013103decoder::new(information))),
5=> return Ok(Box::new( AI01320xDecoder::new(information))),
_=>{},
}
match fourBitEncodationMethod {
4 => return Ok(Box::new(AI013103decoder::new(information))),
5 => return Ok(Box::new(AI01320xDecoder::new(information))),
_ => {}
}
let fiveBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
match fiveBitEncodationMethod {
12=> return Ok(Box::new( AI01392xDecoder::new(information))),
13=> return Ok(Box::new( AI01393xDecoder::new(information))),
_=>{},
}
let fiveBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
match fiveBitEncodationMethod {
12 => return Ok(Box::new(AI01392xDecoder::new(information))),
13 => return Ok(Box::new(AI01393xDecoder::new(information))),
_ => {}
}
let sevenBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
match sevenBitEncodationMethod {
56=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "11".to_owned()))),
57=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "11".to_owned()))),
58=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "13".to_owned()))),
59=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "13".to_owned()))),
60=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "15".to_owned()))),
61=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "15".to_owned()))),
62=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "17".to_owned()))),
63=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "17".to_owned()))),
_=>{},
}
let sevenBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
match sevenBitEncodationMethod {
56 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"11".to_owned(),
)))
}
57 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"11".to_owned(),
)))
}
58 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"13".to_owned(),
)))
}
59 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"13".to_owned(),
)))
}
60 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"15".to_owned(),
)))
}
61 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"15".to_owned(),
)))
}
62 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"17".to_owned(),
)))
}
63 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"17".to_owned(),
)))
}
_ => {}
}
Err(Exceptions::IllegalStateException(format!("unknown decoder: {}" , information)))
Err(Exceptions::IllegalStateException(format!(
"unknown decoder: {}",
information
)))
}

View File

@@ -55,48 +55,58 @@ impl AI01decoder for AI013103decoder<'_> {}
impl<'a> AI013103decoder<'_> {
pub fn new(information: &'a BitArray) -> AI013103decoder<'a> {
AI013103decoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight))
AI013103decoder(AI013x0xDecoder::new(
information,
addWeightCode,
checkWeight,
))
}
}
fn addWeightCode( buf: &mut String, _weight: u32) {
fn addWeightCode(buf: &mut String, _weight: u32) {
buf.push_str("(3103)");
}
fn checkWeight( weight: u32) -> u32 {
fn checkWeight(weight: u32) -> u32 {
weight
}
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
#[cfg(test)]
mod AI013103DecoderTest {
mod AI013103DecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const header: &str = "..X..";
const header :&str = "..X..";
#[test]
fn test0131031() {
let data = format!("{}{}{}", header , compressedGtin900123456798908 , compressed15bitWeight1750);
let expected = "(01)90012345678908(3103)001750";
assertCorrectBinaryString(&data, expected);
fn test0131031() {
let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
let expected = "(01)90012345678908(3103)001750";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test0131032() {
let data = format!("{}{}{}",header , compressedGtin900000000000008 , compressed15bitWeight0);
let expected = "(01)90000000000003(3103)000000";
assertCorrectBinaryString(&data, expected);
fn test0131032() {
let data = format!(
"{}{}{}",
header, compressedGtin900000000000008, compressed15bitWeight0
);
let expected = "(01)90000000000003(3103)000000";
assertCorrectBinaryString(&data, expected);
}
#[test]
#[should_panic]
fn test013103invalid() {
let data = format!("{}{}{}..",header , compressedGtin900123456798908 , compressed15bitWeight1750 );
assertCorrectBinaryString(&data, "");
fn test013103invalid() {
let data = format!(
"{}{}{}..",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
assertCorrectBinaryString(&data, "");
}
}
}

View File

@@ -26,29 +26,30 @@
use super::abstract_decoder_test_utils::*;
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
const header: &str = "..X.X";
const header :&str = "..X.X";
#[test]
fn test0132021() {
let data = format!("{}{}{}",header, compressedGtin900123456798908 , compressed15bitWeight1750);
#[test]
fn test0132021() {
let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
let expected = "(01)90012345678908(3202)001750";
assertCorrectBinaryString(&data, expected);
}
}
#[test]
fn test0132031() {
let data = format!("{}{}{}",header , compressedGtin900123456798908 , compressed15bitWeight11750);
#[test]
fn test0132031() {
let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight11750
);
let expected = "(01)90012345678908(3203)001750";
assertCorrectBinaryString(&data, expected);
}
}

View File

@@ -54,7 +54,11 @@ impl AbstractExpandedDecoder for AI01320xDecoder<'_> {
impl AI01decoder for AI01320xDecoder<'_> {}
impl<'a> AI01320xDecoder<'_> {
pub fn new(information: &'a BitArray) -> AI01320xDecoder<'a> {
AI01320xDecoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight))
AI01320xDecoder(AI013x0xDecoder::new(
information,
addWeightCode,
checkWeight,
))
}
}
@@ -66,10 +70,10 @@ fn addWeightCode(buf: &mut String, weight: u32) {
}
}
fn checkWeight( weight: u32) -> u32 {
fn checkWeight(weight: u32) -> u32 {
if weight < 10000 {
weight
} else {
weight - 10000
}
}
}

View File

@@ -132,103 +132,145 @@ impl<'a> AI013x0x1xDecoder<'_> {
}
}
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
#[cfg(test)]
mod AI013X0X1XDecoderTest {
mod AI013X0X1XDecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const header310x11: &str = "..XXX...";
const header320x11: &str = "..XXX..X";
const header310x13: &str = "..XXX.X.";
const header320x13: &str = "..XXX.XX";
const header310x15: &str = "..XXXX..";
const header320x15: &str = "..XXXX.X";
const header310x17: &str = "..XXXXX.";
const header320x17: &str = "..XXXXXX";
const header310x11 : &str = "..XXX...";
const header320x11 : &str = "..XXX..X";
const header310x13 : &str = "..XXX.X.";
const header320x13 : &str = "..XXX.XX";
const header310x15 : &str = "..XXXX..";
const header320x15 : &str = "..XXXX.X";
const header310x17 : &str = "..XXXXX.";
const header320x17 : &str = "..XXXXXX";
#[test]
fn test01310X1XendDate() {
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 , compressedDateEnd);
let expected = "(01)90012345678908(3100)001750";
assertCorrectBinaryString(&data, expected);
fn test01310X1XendDate() {
let data = format!(
"{}{}{}{}",
header310x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateEnd
);
let expected = "(01)90012345678908(3100)001750";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01310X111() {
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3100)001750(11)100312";
assertCorrectBinaryString(&data, expected);
fn test01310X111() {
let data = format!(
"{}{}{}{}",
header310x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(11)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01320X111() {
let data = format!("{}{}{}{}",header320x11 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3200)001750(11)100312";
assertCorrectBinaryString(&data, expected);
fn test01320X111() {
let data = format!(
"{}{}{}{}",
header320x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(11)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01310X131() {
let data = format!("{}{}{}{}", header310x13 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3100)001750(13)100312";
assertCorrectBinaryString(&data, expected);
fn test01310X131() {
let data = format!(
"{}{}{}{}",
header310x13,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(13)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01320X131() {
let data = format!("{}{}{}{}", header320x13 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3200)001750(13)100312";
assertCorrectBinaryString(&data, expected);
fn test01320X131() {
let data = format!(
"{}{}{}{}",
header320x13,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(13)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01310X151() {
let data = format!("{}{}{}{}", header310x15 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3100)001750(15)100312";
assertCorrectBinaryString(&data, expected);
fn test01310X151() {
let data = format!(
"{}{}{}{}",
header310x15,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(15)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01320X151() {
let data = format!("{}{}{}{}", header320x15 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3200)001750(15)100312";
assertCorrectBinaryString(&data, expected);
fn test01320X151() {
let data = format!(
"{}{}{}{}",
header320x15,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(15)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01310X171() {
let data = format!("{}{}{}{}", header310x17 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3100)001750(17)100312";
assertCorrectBinaryString(&data, expected);
fn test01310X171() {
let data = format!(
"{}{}{}{}",
header310x17,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(17)100312";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn test01320X171() {
let data = format!("{}{}{}{}", header320x17 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
compressedDateMarch12th2010);
let expected = "(01)90012345678908(3200)001750(17)100312";
assertCorrectBinaryString(&data, expected);
fn test01320X171() {
let data = format!(
"{}{}{}{}",
header320x17,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(17)100312";
assertCorrectBinaryString(&data, expected);
}
}
}

View File

@@ -78,8 +78,11 @@ impl<'a> AI013x0xDecoder<'_> {
const HEADER_SIZE: usize = 4 + 1;
const WEIGHT_SIZE: usize = 15;
pub fn new(information: &'a BitArray, addWeightCodeFunction: fn(&mut String, u32),
checkWeightFunction: fn(u32) -> u32,) -> AI013x0xDecoder<'a> {
pub fn new(
information: &'a BitArray,
addWeightCodeFunction: fn(&mut String, u32),
checkWeightFunction: fn(u32) -> u32,
) -> AI013x0xDecoder<'a> {
AI013x0xDecoder {
information,
decoder: GeneralAppIdDecoder::new(information),

View File

@@ -58,7 +58,6 @@ impl<'a> AnyAIDecoder<'_> {
}
}
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
@@ -66,56 +65,77 @@ impl<'a> AnyAIDecoder<'_> {
mod AnyAIDecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const HEADER: &str = ".....";
const HEADER : &str = ".....";
#[test]
fn testAnyAIDecoder1() {
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2numeric , numeric12);
let expected = "(10)12A12";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecoder1() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2numeric, numeric12
);
let expected = "(10)12A12";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn testAnyAIDecoder2() {
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2isoiec646 , i646B);
let expected = "(10)12AB";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecoder2() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2isoiec646, i646B
);
let expected = "(10)12AB";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn testAnyAIDecoder3() {
let data = format!("{}{}{}{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alpha2isoiec646 , i646B , i646C , isoiec6462alpha ,
alphaA , alpha2numeric , numeric10);
let expected = "(10)BCA10";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecoder3() {
let data = format!(
"{}{}{}{}{}{}{}{}{}{}",
HEADER,
numeric10,
numeric2alpha,
alpha2isoiec646,
i646B,
i646C,
isoiec6462alpha,
alphaA,
alpha2numeric,
numeric10
);
let expected = "(10)BCA10";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn testAnyAIDecodernumericFNC1secondDigit() {
let data = format!("{}{}{}",HEADER , numeric10 , numeric1FNC1);
let expected = "(10)1";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecodernumericFNC1secondDigit() {
let data = format!("{}{}{}", HEADER, numeric10, numeric1FNC1);
let expected = "(10)1";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn testAnyAIDecoderalphaFNC1() {
let data = format!("{}{}{}{}{}", HEADER, numeric10 , numeric2alpha , alphaA , alphaFNC1);
let expected = "(10)A";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecoderalphaFNC1() {
let data = format!(
"{}{}{}{}{}",
HEADER, numeric10, numeric2alpha, alphaA, alphaFNC1
);
let expected = "(10)A";
assertCorrectBinaryString(&data, expected);
}
#[test]
fn testAnyAIDecoder646FNC1() {
let data = format!("{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alphaA , isoiec6462alpha , i646B , i646FNC1);
let expected = "(10)AB";
assertCorrectBinaryString(&data, expected);
fn testAnyAIDecoder646FNC1() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric2alpha, alphaA, isoiec6462alpha, i646B, i646FNC1
);
let expected = "(10)AB";
assertCorrectBinaryString(&data, expected);
}
}
}

View File

@@ -197,8 +197,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
}
} //while (!isFinished);
if result.getDecodedInformation().is_some(){ Ok(result.getDecodedInformation().as_ref().unwrap().clone())}
else {Err(Exceptions::NotFoundException("".to_owned()))}
if result.getDecodedInformation().is_some() {
Ok(result.getDecodedInformation().as_ref().unwrap().clone())
} else {
Err(Exceptions::NotFoundException("".to_owned()))
}
}
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {

View File

@@ -52,4 +52,4 @@ mod ai_013103_decoder;
pub use ai_013103_decoder::*;
#[cfg(test)]
mod ai_0132023203_decoder_test;
mod ai_0132023203_decoder_test;

View File

@@ -24,19 +24,19 @@
* http://www.piramidepse.com/
*/
use crate::oned::rss::expanded::{binary_util, decoders::{ abstract_expanded_decoder}};
use crate::oned::rss::expanded::{binary_util, decoders::abstract_expanded_decoder};
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
#[test]
fn testNoAi() {
let information = binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....").expect("build");
#[test]
fn testNoAi() {
let information =
binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....")
.expect("build");
let mut decoder = abstract_expanded_decoder::createDecoder(&information).expect("create");
let decoded = decoder.parseInformation().expect("parsed");
assert_eq!("(10)12A", decoded);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2010 ZXing authors
*
* 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.
*/
use std::fmt::Display;
use super::ExpandedPair;
/**
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
*/
#[derive(Hash)]
pub struct ExpandedRow {
pairs: Vec<ExpandedPair>,
rowNumber: u32,
}
impl ExpandedRow {
pub fn new(pairs: Vec<ExpandedPair>, rowNumber: u32) -> Self {
Self { pairs, rowNumber }
}
pub fn getPairs(&self) -> &[ExpandedPair] {
&self.pairs
}
pub fn getRowNumber(&self) -> u32 {
self.rowNumber
}
pub fn isEquivalent(&self, otherPairs: &[ExpandedPair]) -> bool {
self.pairs == otherPairs
}
}
impl PartialEq for ExpandedRow {
/**
* Two rows are equal if they contain the same pairs in the same order.
*/
fn eq(&self, other: &Self) -> bool {
self.pairs == other.pairs
}
}
impl Display for ExpandedRow {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{{ ")?;
for p in &self.pairs {
write!(f, "{}", p)?;
}
write!(f, " }}") //{:?} }} " , self.pairs )
}
}

View File

@@ -7,4 +7,7 @@ mod expanded_pair;
pub use expanded_pair::*;
#[cfg(test)]
mod expanded_information_decoder_test;
mod expanded_information_decoder_test;
mod expanded_row;
pub use expanded_row::*;