tests/testthat/test-nndiagram_nodeCoverup.R

test_that("nndiagram_nodeCoverup works", {
  expect_equal(nndiagram_nodeCoverup(input=3,hidden=c(6,6),node.coverup = 4), c( "% To make the code work in any 'LaTeX' editor, users need to install and import two 'TeX' packages in the setting, including 'TikZ'. ",
                                                                                 "% Users are recommended to try the output 'LaTeX' code in Overleaf. ",
                                                                                 " ",
                                                                                 "\\usepackage{tikz} ",
                                                                                 "\\def\\layersep{2.5cm} ",
                                                                                 "\\newcommand*\\circled[1]{\\tikz[baseline=(char.base)]{ ",
                                                                                 "  \\node[shape=rectangle,inner sep=3pt, draw=black!100, fill= black!25] (char) {#1};}} ",
                                                                                 " ",
                                                                                 "\\begin{figure}[!ht] ",
                                                                                 "\\centering ",
                                                                                 "\\begin{tikzpicture}[shorten >=1pt,draw=black!100, node distance=\\layersep, scale=1] ",
                                                                                 "  \\tikzstyle{every pin edge}=[<-,shorten <=1pt, draw=black!100]; ",
                                                                                 "  \\tikzstyle{neuron}=[circle, draw=black!100, minimum size=17pt,inner sep=0pt]; ",
                                                                                 "  \\tikzstyle{input neuron}=[neuron]; ",
                                                                                 "  \\tikzstyle{output neuron}=[neuron]; ",
                                                                                 "  \\tikzstyle{hidden neuron}=[neuron]; ",
                                                                                 "  \\tikzstyle{coveruped neuron}=[neuron, draw=black!25]; ",
                                                                                 "  \\tikzstyle{annot} = [text width=4em, text centered, text=black!100] ",
                                                                                 " ",
                                                                                 "  % drawing neurons ",
                                                                                 "  \\foreach \\name / \\y in {1/1,2/2,3/3} ",
                                                                                 "      \\node[input neuron, pin=left:\\textcolor{black!100}{Input \\y}] (I-\\name) at (0,-1.5-\\y) {}; ",
                                                                                 "  \\foreach \\name / \\y in {2/2,3/3,4/4,5/5,6/6} ",
                                                                                 "      \\path[yshift=0cm] ",
                                                                                 "          node[hidden neuron] (H-\\name) at (1* \\layersep,-\\y cm) {}; ",
                                                                                 "  \\foreach \\name / \\y in {7/1,8/2,9/3,10/4,11/5,12/6} ",
                                                                                 "      \\path[yshift=0cm] ",
                                                                                 "          node[hidden neuron] (H-\\name) at (2* \\layersep,-\\y cm) {}; ",
                                                                                 "  \\foreach \\name / \\y in {1/1} ",
                                                                                 "      \\path[yshift=0cm] ",
                                                                                 "          node[coveruped neuron] (H-\\name) at (1* \\layersep,-\\y cm) {}; ",
                                                                                 "  \\node[output neuron,pin={[pin edge={->}]right:\\textcolor{black!100}{Output}}, right of=H-9, yshift=-0.5cm] (O) {}; ",
                                                                                 " ",
                                                                                 "  % drawing arrows ",
                                                                                 "  \\foreach \\source in {1,2,3} ",
                                                                                 "      \\foreach \\dest in {2,3,4,5,6} ",
                                                                                 "          \\path [->] (I-\\source) edge (H-\\dest); ",
                                                                                 "  \\foreach \\source in {1,...,3} ",
                                                                                 "      \\foreach \\dest in {1} ",
                                                                                 "          \\path [->] (I-\\source) edge [draw=black!25] (H-\\dest); ",
                                                                                 "  \\foreach \\source in {2,3,4,5,6} ",
                                                                                 "      \\foreach \\dest in {7,8,9,10,11,12} ",
                                                                                 "          \\path [->] (H-\\source) edge (H-\\dest); ",
                                                                                 "  \\foreach \\source in {1} ",
                                                                                 "      \\foreach \\dest in {7,...,12} ",
                                                                                 "          \\path [->] (H-\\source) edge [draw=black!25] (H-\\dest); ",
                                                                                 "  \\foreach \\source in {7,8,9,10,11,12} ",
                                                                                 "      \\path [->] (H-\\source) edge (O); ",
                                                                                 "",
                                                                                 "   % annotations ",
                                                                                 "  \\node[annot,above of=I-1, node distance=3.5cm] {Input layer}; ",
                                                                                 "  \\node[annot,above of=I-1, node distance=2.5cm] {$\\circled{3}$}; ",
                                                                                 "  \\node[annot,above of=H-1, node distance=2cm] (hl1) {Hidden layer 1}; ",
                                                                                 "  \\node[annot,above of=H-1, node distance=1cm] (hl1) {$\\circled{6}$}; ",
                                                                                 "  \\node[annot,above of=H-7, node distance=2cm] (hl2) {Hidden layer 2}; ",
                                                                                 "  \\node[annot,above of=H-7, node distance=1cm] (hl2) {$\\circled{6}$}; ",
                                                                                 "  \\node[annot,above of =O, node distance=4.5cm] {Output layer}; ",
                                                                                 "  \\node[annot,above of =O, node distance=3.5cm] {$\\circled{1}$}; ",
                                                                                 "",
                                                                                 "\\end{tikzpicture} ",
                                                                                 "\\caption{} ",
                                                                                 "\\label{} ",
                                                                                 "\\end{figure} "                                                                                                                 ))
})

Try the nndiagram package in your browser

Any scripts or data that you put into this service are public.

nndiagram documentation built on April 18, 2023, 5:11 p.m.