From 8bff627fcf81e035fe663706f26a91541e93eb6d Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Sun, 19 Nov 2023 13:03:33 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=AC=20integration=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit example with jconsole: ``` ; jconsole >: 1 2 >: 1 2 3 2 3 4 >: i. 2 2 1 2 3 4 ``` --- tests/t.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/t.rs b/tests/t.rs index 505bfbe..cb4461c 100644 --- a/tests/t.rs +++ b/tests/t.rs @@ -15,6 +15,10 @@ #[test]fn add_slice_to_rotated_slice()->R<()>{ let(a@A{m:4,n:1,..})=eval_s("1 2 3 4 + i. 4 1")? else{bail!("bad dims")};eq!(a.into_matrix()?,&[&[1],&[3],&[5],&[7]]);ok!()} #[test]fn other_add_slice_to_rotated_slice_is_length_error()->R<()>{is!(eval_s("i. 4 1 + 1 2 3 4").is_err());ok!()} +} #[cfg(test)]mod increment{use super::*; + #[test]fn increment_scalar()->R<()>{let(i)=eval_s(">: 1")?; eq!(i.as_i()?, 2); ok!()} + #[test]fn increment_slice ()->R<()>{let(i)=eval_s(">: 1 2 3")?; eq!(i.as_slice()?, &[2,3,4]); ok!()} + #[test]fn increment_matrix()->R<()>{let(i)=eval_s(">: i. 2 2")?;eq!(i.into_matrix()?,&[&[1,2],&[3,4]]);ok!()} } #[cfg(test)]mod tally{use super::*; macro_rules! t{($f:ident,$i:literal,$o:literal)=>{ #[test]fn $f()->R<()>{let(a@A{m:1,n:1,..})=eval_s($i)? else{bail!("bad dims")};eq!(a.as_slice()?,&[$o]);ok!()}}} From 62edb1f8061cdcf859f9335e13fb6c104718a4e5 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Sun, 19 Nov 2023 13:25:03 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=A0=20`>:`=20increment=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/a.rs | 1 + src/j.rs | 4 ++-- src/r.rs | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/a.rs b/src/a.rs index 14b3029..aa29f70 100644 --- a/src/a.rs +++ b/src/a.rs @@ -138,6 +138,7 @@ use super::*; use std::marker::PhantomData as PD; pub fn m_tally(self)->R{let A{m,n,..}=self;let(i)=I::try_from(m*n)?;A::from_i(i)} pub fn m_trans(self)->R{let(i@A{m:m_i,n:n_i,..})=self;let(m_o,n_o)=(n_i,m_i); let(f)=|i_o,j_o|{i.get(j_o,i_o)};A::new(m_o,n_o)?.init_with(f)} + pub fn m_inc(self)->R{let(a@A{m,n,..})=self;A::new(m,n)?.init_with(|i,j|a.get(i,j).map(|x|x+1))} } /**dyadic verbs*/impl D{ diff --git a/src/j.rs b/src/j.rs index 4d09ead..20d7c6b 100644 --- a/src/j.rs +++ b/src/j.rs @@ -9,8 +9,8 @@ fn eval_(ast:B,st:&mut ST)->R>{use{M::*,D::*}; Ok(None)=>Err(err!("expression did not result in a value"))}}; match *ast{ N::A{a} =>Ok(a), - N::M{m,o} =>{let(a)=rec(o)?; match m{Idot=>a.m_idot(), Shape=>a.m_shape(), Same=>a.m_same(), - Tally=>a.m_tally(),Transpose=>a.m_trans()}} + N::M{m,o} =>{let(a)=rec(o)?; match m{Idot=>a.m_idot(), Shape=>a.m_shape(), Same=>a.m_same(), + Tally=>a.m_tally(),Transpose=>a.m_trans(), Inc=>a.m_inc()}} N::D{d,l,r}=>{let(l,r)=(rec(l)?,rec(r)?);match d{Plus=>l.d_plus(r), Mul=>l.d_mul(r), Left=>l.d_left(r), Right=>l.d_right(r)}} N::Ym{ym,d,o}=>{rec(o).and_then(|a|ym.apply(d,a))} diff --git a/src/r.rs b/src/r.rs index 875338b..45820b2 100644 --- a/src/r.rs +++ b/src/r.rs @@ -32,8 +32,8 @@ mod lex{use crate::*; t!(lex_assign, "a =: 1", v![sy!("a"), T::E, TA(v![1])] ); } }/**input parsing*/mod parse{use {crate::*,super::lex::{T,lex}}; - /**dyadic verb */ #[derive(DBG,PE,PO)] pub enum D {Plus,Mul, Left, Right } - /**monadic verb */ #[derive(DBG,PE,PO)] pub enum M {Idot,Shape,Tally,Transpose,Same} + /**dyadic verb */ #[derive(DBG,PE,PO)] pub enum D {Plus,Mul, Left, Right } + /**monadic verb */ #[derive(DBG,PE,PO)] pub enum M {Idot,Shape,Tally,Transpose,Same,Inc} /**dyadic adverb */ #[derive(DBG )] pub enum Yd{/**dyadic `/` */ Table , /**dyadic `\` */ Infix } /**monadic adverb */ #[derive(DBG )] pub enum Ym{/**monadic `/`*/ Insert, @@ -104,7 +104,7 @@ mod lex{use crate::*; impl M {fn new(s:&str)->O {use M::*; Some(match s{"i."=>Idot ,"$" =>Shape ,"|:"=>Transpose , "#" =>Tally ,"[" =>Same ,"]" =>Same , - _=>r!(None)})}} + ">:"=>Inc, _=>r!(None)})}} impl D {fn new(s:&str)->O {use D::*; Some(match s{"+" =>Plus ,"*" =>Mul ,"[" =>Left , "]" =>Right , _=>r!(None)})}} impl Ym{fn new(s:&str)->O{use Ym::*;Some(match s{"/" =>Insert,"\\"=>Prefix, _=>r!(None)})}}