4c11d1e61ffdaff157834bb6efde3ffef9c7a314
[course.git] / asymptote / Circ-test.asy
1 /* Test suite for Circ.asy.
2  *
3  * Copyright (C) 2008-2009 W. Trevor King <wking@drexel.edu>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 import Circ;
21
22 real u = 2cm, v=0;
23
24 write("resistor");
25 TwoTerminal Rn = resistor((0,v), normal, 0, "$R_{normal}$", "30\ohm");
26 dot("beg", Rn.beg, NW);
27 dot("end", Rn.end, NE);
28 dot("mid", Rn.mid, S);
29 TwoTerminal Rvb = resistor((2u,v), variable, 0, "$R_{variable}$", "30\kohm");
30 v -= u;
31
32 write("capacitor");
33 TwoTerminal Cn = capacitor((0,v), normal, 0, "$C_{normal}$", "30 $\mu$F");
34 TwoTerminal Ce = capacitor((u,v), electrolytic, 0, "$C_{electrolytic}$", "30 $\mu$F");
35 TwoTerminal Cvb = capacitor((2u,v), variable, 0, "$C_{variable}$", "30 $\mu$F");
36 TwoTerminal Cvt = capacitor((3u,v), variant, 0, "$C_{variant}$", "30 $\mu$F");
37 v -= u;
38
39 write("inductor");
40 TwoTerminal Lup = inductor((0,v), Up, 0, "$L_{Up}$", "30 H");
41 TwoTerminal Ldown = inductor((u,v), Down, 0, "$L_{Down}$", "30 H");
42 v -= u;
43
44 write("diode");
45 TwoTerminal Dn = diode((0,v), normal, 0, "$D_{normal}$", "1.3 V");
46 TwoTerminal Dz = diode((u,v), zener, 0, "$D_{zener}$", "1.3 V");
47 TwoTerminal Dled = diode((2u,v), LED, 0, "$D_{LED}$", "1.7 V");
48 v -= u;
49
50 write("battery");
51 TwoTerminal B = battery((0,v), 0, "Battery", "1.5 V");
52 v -= u;
53
54 write("switch");
55 TwoTerminal B = switchSPST((0,v), NO, 0, "$S_{NO}$", "Open");
56 TwoTerminal B = switchSPST((u,v), NC, 0, "$S_{NC}$", "Closed");
57 v -= u;
58
59 write("current");
60 TwoTerminal Icurr = current((0,v), 0, "I", "10 A");
61 v -= u;
62
63 write("source");
64 TwoTerminal Sdc = source((0,v), DC, 0, "DC", "5 V");
65 TwoTerminal Sac = source((u,v), AC, 0, "AC", "5 V$_{pp}$");
66 TwoTerminal Si = source((2u,v), I, 0, "I", "5 A");
67 TwoTerminal Sv = source((3u,v), V, 0, "V", "5 V");
68 v -= 1.5u;
69
70 write("positioning");
71 TwoTerminal Spos = source((u,v), DC, 90, "DC", "5 V");
72 TwoTerminal Rpos = resistor((0,0), normal, 0, "+offset", "5 \ohm", draw=false);
73 Rpos.centerto(Spos.beg, Spos.end, offset=u);
74 Rpos.draw();
75 dot("Sa", Spos.beg, S);
76 dot("Sb", Spos.end, N);
77 dot("Ra", Rpos.beg, S);
78 dot("Rb", Rpos.end, N);
79 TwoTerminal Cpos = capacitor((0,0), normal, 0, "-2offset", "4 F",draw=false);
80 Cpos.centerto(Spos.beg, Spos.end, offset=-2u);
81 Cpos.draw();
82 v -= u;