function upc_check_digit_calculate_test ( ) %*****************************************************************************80 % %% UPC_CHECK_DIGIT_CALCULATE_TEST tests UPC_CHECK_DIGIT_CALCULATE. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 04 October 2015 % % Author: % % John Burkardt % fprintf ( 1, '\n' ); fprintf ( 1, 'UPC_CHECK_DIGIT_CALCULATE_TEST\n' ); fprintf ( 1, ' UPC_CHECK_DIGIT_CALCULATE calculates the 12-th digit\n' ); fprintf ( 1, ' (the check digit) of a UPC.\n' ); fprintf ( 1, '\n' ); % % Supply the full code, with dashes. % s1 = '6-39382-00039-3'; d1 = 3; d2 = upc_check_digit_calculate ( s1 ); fprintf ( 1, ' Check digit of "%s" is %d, expecting %d\n', s1, d2, d1 ); % % Supply a partial code, with spaces. % s1 = '0 43000 18170'; d1 = 6; d2 = upc_check_digit_calculate ( s1 ); fprintf ( 1, ' Check digit of "%s" is %d, expecting %d\n', s1, d2, d1 ); % % Supply a partial code, no spaces. % s1 = '30074660601'; d1 = 7; d2 = upc_check_digit_calculate ( s1 ); fprintf ( 1, ' Check digit of "%s" is %d, expecting %d\n', s1, d2, d1 ); % % Supply a partial code, no spaces. % s1 = '24689753124'; d1 = 5; d2 = upc_check_digit_calculate ( s1 ); fprintf ( 1, ' Check digit of "%s" is %d, expecting %d\n', s1, d2, d1 ); % % Supply a partial code, no spaces. % s1 = '13579864213'; d1 = 9; d2 = upc_check_digit_calculate ( s1 ); fprintf ( 1, ' Check digit of "%s" is %d, expecting %d\n', s1, d2, d1 ); return end